【发布时间】:2015-08-11 20:51:06
【问题描述】:
我在数据库中有 700 多个地址。 我想明智地绘制它们的区域。 我已经实现了这段代码:
public LatLng getSingleLocationFromAddress(String strAddress)
{
Geocoder coder = new Geocoder(this, Locale.getDefault());
List<Address> address = null;
Address location = null;
GeoPoint p1 = null;
LatLng temp = null;//new LatLng(26.0000, 121.0000);
String strAddresNew = strAddress.replace(",", " ");
try
{
address = coder.getFromLocationName(strAddresNew, 1);
if (!address.isEmpty())
{
location = address.get(0);
location.getLatitude();
location.getLongitude();
temp = new LatLng(location.getLatitude(), location.getLongitude());
Log.d("Latlng : ", temp + "");
} else
{
arrTemp.add(strAddress);
System.out.println(arrTemp);
}
} catch (IOException e)
{
Toast.makeText(mContext, e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
}
return temp;
}
但问题是当我像这样在循环中调用此方法时:
Marker TP1 = googleMap.addMarker(new MarkerOptions().position(getSingleLocationFromAddress(fullAddress)));
coder.getFromLocationName(strAddresNew, 1); 行对某些地址返回 null,例如,如果我有 7 个地址的 ArrayList,那么我只会得到 4-5 个 LatLong 值。
【问题讨论】:
-
...请查看我的以下解决方案
-
嗯,我看到了你现在面临的问题。如果无法从地址中获取位置,则无法获取纬度/经度。
-
它不会返回 LatLng 提供的位置名称。每个 LatLng 都没有位置名称。
-
现有的 API 将返回地址的纬度和经度。也许会考虑使用其中之一?
标签: android google-maps reverse-geocoding