android - 当从地址中找到经纬度时,如何给出地址?

标签 android google-maps

我按照这个问题(How can I find the latitude and longitude from address?)并尝试获取地址的纬度和经度。我将该方法称为“GeoPoint point=getLocationFromAddress("colombo,sri lanka");” 。但给出空值。如何正确调用方法?

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((int) (location.getLatitude() * 1E6),
                  (int) (location.getLongitude() * 1E6));

return p1;
}
}

最佳答案

我认为你应该使用谷歌地点自动完成/地点选择器 API。 选择地点,然后您可以获得纬度和经度。 看一下这个: https://developers.google.com/places/android-api/autocomplete

关于android - 当从地址中找到经纬度时,如何给出地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34786019/

相关文章:

android - 访问本地主机(Xamarin)

java - 我如何监听 Google MapView 中覆盖项目的 LongClick?

android - 使用 keytool 在 android 中使用谷歌地图

ios - IOS中Storyboard中如何添加GMSMapView

android - Activity 的昏暗背景

android - 某些 Android 手机无法打开自定义文件扩展名

Android动画不重复

android - 有没有办法选择一个 zip 文件以使用存储访问框架打开?

google-maps - 从谷歌地图流量中获取历史数据

javascript - 为什么我的 WordPress 主题中出现 Google map JavaScript 错误?