Skip to content Skip to sidebar Skip to footer

On Map Region Change In Mapview Android Sdk

I am implementing a Map Kit based application in Android. I was very new to this sdk. My problem is that I need to fire a method when the Map Region changed. Can you guys please le

Solution 1:

the map region will change when the map perform pan or zoom methods but you cannot obtain any info from this methods, so you can doit through the onDraw method. To achieve this you have to subclass the MapView and overrides the onDraw method.

if you do this you can obtain the four coordinates that limits the region displayed, with Projection class retrieveing coordinates for each point ( top-left[0,0], top-right[width-0], bottom-left[0,height] and bottom-right[width,height] ).

in example, in the first onDraw: you get this four coordinates, GeoPoint[4] init in the second run of onDraw you get the new four coordinates, GeoPoint[4] end, so here you can compare the regions.

this is a expensive operation so a delay mechanism will be helpful to slowdown the changes detection...

Solution 2:

You can use MapView's onCameraChange event like below:

finalFragmentmapFragment= getFragmentManager().findFragmentById(R.id.map); 
mMap =  ((MapFragment)mapFragment).getMap();
mMap.setOnCameraChangeListener(newOnCameraChangeListener() {

    @OverridepublicvoidonCameraChange(CameraPosition position) {
        Pointpoint=newPoint(mapFragment.getView().getWidth() / 2 , mapFragment.getView().getHeight()/2);
        LatLngl= mMap.getProjection().fromScreenLocation(point);
        Log.v("asd","center lat: " + l.latitude + " center long: " + l.longitude + " ");

    }
});

Post a Comment for "On Map Region Change In Mapview Android Sdk"