2014-03-12 32 views
0

中的地址位置获得结果和失败我正在开发android应用程序,其中我使用编辑文本中的目的地,并且我想要输入位置的纬度和经度。如何通过android

exmaple:我已经输入了编辑文本pune,现在我想要它的经纬度。

回答

0

从这里:https://stackoverflow.com/a/3574792/2065418

Geocoder coder = new Geocoder(this); 
    List<Address> address; 

    try { 
     address = coder.getFromLocationName(strAddress,5); 
     if (address == null) { 
      return null; 
     } 
     Address location = address.get(0); 
     location.getLatitude(); 
     location.getLongitude(); 

     p1 = new GeoPoint((int) (location.getLatitude() * 1E6), 
          (int) (location.getLongitude() * 1E6)); 

     return p1; 
    } 

strAddress是包含地址的字符串。 address变量保存转换后的地址。