开发者

Geocoding Code not Working - Googlemaps

开发者 https://www.devze.com 2023-04-04 03:14 出处:网络
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 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> foundA开发者_如何学JAVAdresses = 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.


Either you address is not in Google maps address database or your app does not have internet access privileges.

  1. Check in http://maps.google.com that the address is actually found.

  2. That yor app has internet access privileges. You must have this in ypur app manifest:

    <uses-permission android:name="android.permission.INTERNET" />
    
0

精彩评论

暂无评论...
验证码 换一张
取 消