2012-11-30 129 views
1

如何通过获取位置PIN码在编辑文本我输入城市名称或城市PIN码它会使用谷歌地图Android中 例如 地址输入查找纬度和经度显示它的经度和纬度。Android的谷歌地图

回答

1

这是一个非常简单的解决方案, 假设地理编码服务都存在:

final Geocoder geocoder = new Geocoder(this); 
final String zip = "90210"; 
try { 
    List<Address> addresses = geocoder.getFromLocationName(zipCode, 1); 
    if (addresses != null && !addresses.isEmpty()) { 
    Address address = addresses.get(0); 
    // Use the address as needed 
    String message = String.format("Latitude: %f, Longitude: %f", 
    address.getLatitude(), address.getLongitude()); 
    Toast.makeText(this, message, Toast.LENGTH_LONG).show(); 
    } else { 
    // Display appropriate message when Geocoder services are not available 
    Toast.makeToast(this, "Unable to geocode zipcode", Toast.LENGTH_LONG).show(); 
    } 
} catch (IOException e) { 
    // handle exception 
} 

//地址

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; 
} 

http://android-er.blogspot.in/2011/02/get-address-from-location-using.html

+0

如何获得lat&lng邮政编码... – appukrb