例如:经度:10.123456 纬度:20.654321
根据以上坐标获取到实际位置(不借用百度地图或高德地图的API)
代码如下:
-
//放入经纬度就可以了
-
public String getAddress(double latitude, double longitude) {
-
Geocoder geocoder = new Geocoder( this, Locale.getDefault());
-
-
try {
-
List<Address> addresses = geocoder.getFromLocation(latitude,
-
longitude, 1);
-
if (addresses.size() > 0) {
-
Address address = addresses.get( 0);
-
String data = address.toString();
-
int startCity = data.indexOf( "1:\"") + "1:\"".length();
-
int endCity = data.indexOf( "\"", startCity);
-
String city = data.substring(startCity, endCity);
-
-
int startPlace = data.indexOf( "feature=") + "feature=".length();
-
int endplace = data.indexOf( ",", startPlace);
-
String place = data.substring(startPlace, endplace);
-
return city + place ;
-
}
-
} catch (IOException e) {
-
e.printStackTrace();
-
}
-
return "获取失败";
-
}
本文出自 “移动平台开发” 博客,请务必保留此出处http://liuxudong1001.blog.51cto.com/10877072/1749869