0 Replies - 441 Views - Last Post: 16 November 2011 - 08:51 AM

#1 xxiz20000   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-October 11

Question about adding multiple markers in Google map

Posted 16 November 2011 - 08:51 AM

Below codes show how i add an marker on the google map. But i dont know how to add multiple markers on the map, i have a Mysql database stored a lot of latitudes and logtitudes, i still have lots of markers need to be add, how can i do?

package irdc.googlemap;

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.MapView.LayoutParams;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;import android.graphics.Point;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

public class GooglemapActivity extends MapActivity 
{        
	MapView mapView;
	
    MapController mc;    
    GeoPoint p;
    
    /**add pin**/	
    class MapOverlay extends com.google.android.maps.Overlay    
    {        
    	@Override        
    	public boolean draw(Canvas canvas, MapView mapView,
    			boolean shadow, long when)         
    	{            
    		super.draw(canvas, mapView, shadow);
    		//---translate the GeoPoint to screen pixels---
    		Point screenPts = new Point();            
    		mapView.getProjection().toPixels(p, screenPts);
    		//---add the marker---            
    		Bitmap bmp = BitmapFactory.decodeResource(                
    				getResources(), R.drawable.red);
    		canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
    		return true;        
    		}    
    	 
    }
	/** Called when the activity is first created. */    
	@Override    
	public void onCreate(Bundle savedInstanceState)    
	{        
		super.onCreate(savedInstanceState);        
		setContentView(R.layout.main);

		/**set zoom**/
		mapView = (MapView) findViewById(R.id.mapView);        
		LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);          
		View zoomView = mapView.getZoomControls();          
		zoomLayout.addView(zoomView,             
		new LinearLayout.LayoutParams(                
				LayoutParams.WRAP_CONTENT,                 
				LayoutParams.WRAP_CONTENT));         
		mapView.displayZoomControls(true);
		
		/**set street view**/
		mapView.setStreetView(true);
		
		
		/**set Displaying a Particular Location**/
		mc = mapView.getController();
		String coordinates[] = {"22.31658708869768", "114.18028593063354"};
		double lat = Double.parseDouble(coordinates[0]);
		double lng = Double.parseDouble(coordinates[1]);
		p = new GeoPoint(
				(int) (lat * 1E6),
				(int) (lng * 1E6));
		mc.animateTo(p);
		mc.setZoom(17);
		mapView.invalidate();
		
		/**add pin**/
		mc.animateTo(p);
		mc.setZoom(17);
		//---Add a location marker---
		MapOverlay mapOverlay = new MapOverlay();
		List<Overlay> listOfOverlays = mapView.getOverlays();
		listOfOverlays.clear();
		listOfOverlays.add(mapOverlay);
		mapView.invalidate()
	}     
	@Override    
	protected boolean isRouteDisplayed() 
	{        
		return false;    
		}
} 



Is This A Good Question/Topic? 0
  • +

Page 1 of 1