如何从地址找到纬度和经度?我想在谷歌地图上显示地址的位置。如何使用GoogleMaps API获取地址的纬度和经度?
3 回答
ABOUTYOU
TA贡献1812条经验 获得超5个赞
public GeoPoint getLocationFromAddress(String strAddress){Geocoder coder = new Geocoder(this);List<Address> address;GeoPoint p1 = null;try { address = coder.getFromLocationName(strAddress,5); if (address==null) { return null; } Address location=address.get(0); location.getLatitude(); location.getLongitude(); p1 = new GeoPoint((double) (location.getLatitude() * 1E6), (double) (location.getLongitude() * 1E6)); return p1; }}
strAddress
address
扬帆大鱼
TA贡献1799条经验 获得超9个赞
注:
强制性:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><uses-permission android:name="android.permission.INTERNET"/>
最新情况:
public LatLng getLocationFromAddress(Context context,String strAddress) { Geocoder coder = new Geocoder(context); List<Address> address; LatLng p1 = null; try { // May throw an IOException address = coder.getFromLocationName(strAddress, 5); if (address == null) { return null; } Address location = address.get(0); p1 = new LatLng(location.getLatitude(), location.getLongitude() ); } catch (IOException ex) { ex.printStackTrace(); } return p1;}
- 3 回答
- 0 关注
- 565 浏览
添加回答
举报
0/150
提交
取消