Android map view example

main.xml


to generate your map keyClick here

Manifest.xml

    

    
        
            
                
                
            
        
  
    
    


HelloItemizedOverlay.java
package monstercodz.blogspot.com;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay{
 
 private ArrayList mOverlays = new ArrayList();
 private Context mContext;
 public HelloItemizedOverlay(Drawable defaultMarker,Context context) {
  super(boundCenterBottom(defaultMarker));
  // TODO Auto-generated constructor stub
  mContext = context;
 }
 
  public void addOverlay(OverlayItem overlay){
  mOverlays.add(overlay);
  populate();
  }

 @Override
 protected OverlayItem createItem(int i) {
  // TODO Auto-generated method stub
  return mOverlays.get(i);
 }

 @Override
 public int size() {
  // TODO Auto-generated method stub
  return mOverlays.size();
 }
 
 @Override
 protected boolean onTap(int index) {
  // TODO Auto-generated method stub
   OverlayItem item = mOverlays.get(index);
   AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
   dialog.setTitle(item.getTitle());
   dialog.setMessage(item.getSnippet());
   dialog.show();
   return true;
 }

}

MapViewExample.java
package monstercodz.blogspot.com;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class MapViewExample extends MapActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        List mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
        HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
        GeoPoint point = new GeoPoint(30443769,-91158458);
        OverlayItem overlayitem = new OverlayItem(point, "Laissez les bon temps rouler!", "I'm in Louisiana!");

        GeoPoint point2 = new GeoPoint(17385812,78480667);
        OverlayItem overlayitem2 = new OverlayItem(point2, "Namashkaar!", "I'm in Hyderabad, India!");

        itemizedoverlay.addOverlay(overlayitem);
        itemizedoverlay.addOverlay(overlayitem2);

        mapOverlays.add(itemizedoverlay);
    }

 @Override
 protected boolean isRouteDisplayed() {
  // TODO Auto-generated method stub
  return false;
 }
}

marker.png

Download source code example here

0 comments:

Post a Comment