Android根据已知的经纬度坐标获取当前位置

例如:经度:10.123456   纬度:20.654321

           

根据以上坐标获取到实际位置(不借用百度地图或高德地图的API)


代码如下:

  1. //放入经纬度就可以了
  2. public String getAddress(double latitude, double longitude) {
  3. Geocoder geocoder = new Geocoder( this, Locale.getDefault());
  4. try {
  5. List<Address> addresses = geocoder.getFromLocation(latitude,
  6. longitude, 1);
  7. if (addresses.size() > 0) {
  8. Address address = addresses.get( 0);
  9. String data = address.toString();
  10. int startCity = data.indexOf( "1:\"") + "1:\"".length();
  11. int endCity = data.indexOf( "\"", startCity);
  12. String city = data.substring(startCity, endCity);
  13. int startPlace = data.indexOf( "feature=") + "feature=".length();
  14. int endplace = data.indexOf( ",", startPlace);
  15. String place = data.substring(startPlace, endplace);
  16. return city + place ;
  17. }
  18. } catch (IOException e) {
  19. e.printStackTrace();
  20. }
  21. return "获取失败";
  22. }



本文出自 “移动平台开发” 博客,请务必保留此出处http://liuxudong1001.blog.51cto.com/10877072/1749869

猜你喜欢

转载自blog.csdn.net/jason_hd/article/details/80953953
今日推荐