tags:

views:

51

answers:

1

Hi,

I created a custom map in Google Maps "My Maps". Now i want to show that map on an android device, but not just opening it as a web page but showing it using MapView or smth similar. I want to be able to center on a place I have marked on the map etc. My custom map is a map containing the location of all gas stations in a city.

Can someone please point me to the right direction or to an article describing this (I couldn't find anything).

A: 

What i can understand is that u need to create Map app which u can show on ur device and u need list of all Gas station on that map. Is it write? you can do it by making marker on that particular point if u know the Lat and long of that place.

public class helloMap extends MapActivity { /** Called when the activity is first created. */

MapView mapView; 
MapController mc;
GeoPoint p;
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.pushpin);            
        canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);         
        return true;
    }

    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
        //---when user lifts his finger---
        if (event.getAction() == 1) {                
            GeoPoint p = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());
                Toast.makeText(getBaseContext(), 
                    p.getLatitudeE6() / 1E6 + "," + 
                    p.getLongitudeE6() /1E6 , 
                    Toast.LENGTH_SHORT).show();
        }                            
        return false;
    }        

} 



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

    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);

    mc = mapView.getController();
    String coordinates[] = {"22.70", "72.80"};
    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(6); 
    mapView.invalidate();

}

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

}...

If u want to store location then u can store in pair a lat,long of that particular gas station..

Even if u dont know lat and long then u can do it by using GeoCoder Class..

Is that answer your question

Rakesh Gondaliya