1

When I run my app on my emulator, the Google Maps API runs perfectly fine, but when I zoom in it doesn't focus or render like the web version does.

Any ideas?

Here my code:

@Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);
        setContentView(R.layout.map);

        Button openDrawer = (Button) findViewById(R.id.openDrawer);
        openDrawer.setOnClickListener(this);

        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
        MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable, this);

        GeoPoint point = new GeoPoint(19240000,-99120000);
        OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");

        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
    }
jnthnjns
  • 8,962
  • 4
  • 42
  • 65
user1513687
  • 173
  • 2
  • 13

2 Answers2

0

have you try below code???

MapController controller = mapView.getController();
controller.setZoom(15);
controller.setCenter(point);
Hardik Nadiyapara
  • 2,436
  • 2
  • 17
  • 24
  • Can I ask how what I can replace "point" with to make it so it centers on wherever the user's location is? – user1513687 Sep 28 '12 at 13:54
  • I actually put that in, and just centered it on my ItemOverlay. The zoom works right, but the map isn't showing up anymore. – user1513687 Sep 28 '12 at 13:57
0

I believe all you need to do is call mapView.invalidate(), I set up my maps a little differently then yours, I have copied my code below for reference:

LocationManager jLocManager;
MapController mController;
GeoPoint geoP;
MapView mapView;
MyLocationOverlay myLocOverlay;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maps);

    try {
        JJMapsInitialize();
    }catch(Exception e){
        Log.e("JJMapsInitialize", "FAILED: " + e.getMessage());
    }

    myLocOverlay = new MyLocationOverlay(this, mapView);
    myLocOverlay.enableMyLocation();
    mapView.getOverlays().add(myLocOverlay);

}

public void findMyLocation() {
    LocationManager jLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // 35000 is 35 seconds to find location && 10 is the minimum distance in meters
    jLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 10, this.jLocListener);
    jLocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 3000, 10, this.jLocListener);
}

private void JJMapsInitialize() {
    try { 
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.displayZoomControls(true);
        mapView.setBuiltInZoomControls(true);
        mController.animateTo(geoP);
        mController.setZoom(10);
        mapView.invalidate();
    } catch(Exception e) {
        Log.e("JJMapsInitialize", "FAILED: " + e.getMessage());
    }

    try {
        findMyLocation();
    } catch (Exception e) {
        Log.e("findMyLocation", "FAILED: " + e.getMessage());
    }
}

As you can see I call the initialize method in which I set up my MapView with controls, invalidate and then add my overlays.


EDIT

jLocListener is just my LocationListener() - My first name starts with a "j" so I generally use my initial or both initials in my naming conventions.

public LocationListener jLocListener = new LocationListener() {
        //class findMe implements LocationListener {
        public void onLocationChanged(Location location) {
            try {
                lat = location.getLatitude();
                lon = location.getLongitude();
            } catch (Exception e) {
                Log.e("onLocationChanged", "FAILED: " + e.getMessage());
            }
        }
        public void onProviderDisabled(String provider) {
            Log.i("LocationListener", "onProviderDisabled");
        }
        public void onProviderEnabled(String provider) {
            Log.i("LocationListener", "onProviderEnabled");
        }
        public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.i("LocationListener", "onStatusChanged");
        }

    };
jnthnjns
  • 8,962
  • 4
  • 42
  • 65
  • I copied your code into there, but the maps API still doesn't focus correctly. When I zoom in, the map just becomes really grainy. – user1513687 Sep 28 '12 at 16:47
  • How is your internet connection? To even load the initial map you should have a connection which tells me your calling `android.permission.INTERNET` in your manifest correctly, but just wanted to make sure. If you're uncertain feel free to add your permissions you have in your manifest to your question above. – jnthnjns Sep 28 '12 at 16:54
  • Could this error have anything to do with it? 09-28 12:56:46.443: E/MapActivity(4307): Couldn't get connection factory client – user1513687 Sep 28 '12 at 17:01
  • Yes, that is your issue. Check out [this](http://stackoverflow.com/a/7982578/1134705), it *may* help (Make sure to read the comments on the answer as well), this goes back to your manifest. You have an API key also, correct? The [debug certificate](https://developers.google.com/maps/documentation/android/mapkey#getdebugfingerprint)? – jnthnjns Sep 28 '12 at 17:06
  • Yes I have the debug certificate because the API doesn't work on my phone. – user1513687 Sep 28 '12 at 17:06
  • What do you mean "because the API doesn't work on my phone", I develop applications for a tablet and I run the debug key on the device, I never use the emulator. The debug key is for pre-app-signing. – jnthnjns Sep 28 '12 at 17:09
  • I signed my app and got the API key, but when I try to run my app on my phone, the maps do not display. I had this problem with the emulator but I fixed it by signing it. – user1513687 Sep 28 '12 at 17:11