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