地理编码代码不起作用 - Googlemaps
我正在尝试使用地理编码来获取地址,计算出经度和纬度,然后在地图上显示叠加层。
我正在使用下面的代码,但是日志条目 Log.e("Found",""+lat);永远不会触发,我不知道为什么。有人可以帮忙吗?
谢谢 !
private void showpins() throws IOException {
Geocoder gc = new Geocoder(this);
String Address = "Oxford Street, London";
Log.e("Lat",""+Address);
List<Address> foundAdresses = gc.getFromLocationName(Address, 5); //Search addresses
int lat;
int lon;
for (int i = 0; i < foundAdresses.size(); ++i) {
Address x = foundAdresses.get(i);
lat = (int) x.getLatitude();
lon = (int) x.getLongitude();
Log.e("Found",""+lat);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.pushpin);
CustomizedItemOverlay itemizedOverlay =
new CustomizedItemOverlay(drawable, this);
GeoPoint point = new GeoPoint(lat, lon);
OverlayItem overlayitem =
new OverlayItem(point, "Hello", "Location");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
}
}
I am trying to use geocoding to take an address, work out the longitude and latitude and then display an overlay on the map.
I am using the below code, however the log entry Log.e("Found",""+lat); never triggers and I'm not sure why. Can anybody help ?
Thanks !
private void showpins() throws IOException {
Geocoder gc = new Geocoder(this);
String Address = "Oxford Street, London";
Log.e("Lat",""+Address);
List<Address> foundAdresses = gc.getFromLocationName(Address, 5); //Search addresses
int lat;
int lon;
for (int i = 0; i < foundAdresses.size(); ++i) {
Address x = foundAdresses.get(i);
lat = (int) x.getLatitude();
lon = (int) x.getLongitude();
Log.e("Found",""+lat);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.pushpin);
CustomizedItemOverlay itemizedOverlay =
new CustomizedItemOverlay(drawable, this);
GeoPoint point = new GeoPoint(lat, lon);
OverlayItem overlayitem =
new OverlayItem(point, "Hello", "Location");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在某些模拟器 API 级别中,这确实存在问题。请参阅问题 8816:服务不可用。例如,API 级别 8 将不起作用。我发现如果调用该方法两次,API 级别 7 就可以了。我不知道真实设备上的行为。我不认为 Google 保证该服务将始终可用。
There are definite issues with this in certain emulator API levels. See Issue 8816: service not available. For example API level 8 won't work. I find that API level 7 is OK if you call the method twice. The behaviour on real devices is not known to me. I don't think Google guarantee that the service will always be available.
您的地址不在Google Maps地址数据库中,或者您的应用程序没有Internet访问权限。
在 http://maps.google.com 实际上找到了地址。
您的应用程序具有Internet访问权限。您必须在YPUR应用程序清单中使用此内容:
Either you address is not in Google maps address database or your app does not have internet access privileges.
Check in http://maps.google.com that the address is actually found.
That yor app has internet access privileges. You must have this in ypur app manifest: