Tuesday, October 15, 2013

Google Map V2 Android Tips and Ticks for beginners

1) How to set zoom controls?
googleMap.setOnCameraChangeListener(new OnCameraChangeListener() {
           
     public void onCameraChange(CameraPosition arg0) {
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(8));
        googleMap.setOnCameraChangeListener(MySampleMapActivity.this);
      }
});
2) How to add marker at certain point?
mapView.addMarker(new MarkerOptions().position(new LatLng(lat, lng))
.title(dealTitle)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_menu_directions))
.snippet(dealPrice)
);
3) How to display my location icon?
googleMap.setMyLocationEnabled(true);
4) How to set map type?
a. googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
b. googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
 
c. googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
d. googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
5) How to animate to certain position?
final LatLng pos = new LatLng(LAT, LNG);
googleMap.setOnCameraChangeListener(new OnCameraChangeListener() {
        public void onCameraChange(CameraPosition arg0) {
            googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(pos, 11));
        }
    });
6) How to add multiple points?

final LatLngBounds.Builder builder = new LatLngBounds.Builder();
//Number of latitude and longitude in for loop
for(;;){
final LatLng pos = new LatLng(lat,lng);
 builder.include(pos);
googleMap.addMarker(new MarkerOptions()
                        .position(pos)
                        .title("TITLE")
                        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
}

Then,
googleMap.setOnCameraChangeListener(new OnCameraChangeListener() {
               
                public void onCameraChange(CameraPosition arg0) {
                    googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 20);
                    googleMap.setOnCameraChangeListener(null);
                }
            });
7) HOw to add info window?
static final LatLng MY_LOCATION = new LatLng(LAT, LNG);
Marker pune = mMap.addMarker(new MarkerOptions()
                          .position(Pune)
                          .title("Pune")
                          .snippet("YOUR TEXT HERE")
                         .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

Source:  http://mobisys.in/blog/2013/04/google-maps-android-api-v2-different-operations/

No comments:

Post a Comment