Map marker


main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.google.android.maps.MapView
android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:enabled="true"
     android:clickable="true"
        android:apiKey="00HNoqaMrA3CJ71Nj-L_bHf3Q0S6BvAcU0rp6ww"
    />

</LinearLayout>


MyActivity.java


package moor.android.mapmarker;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import com.google.android.maps.*;


import java.util.List;

public class MyActivity extends MapActivity

{
   
    double            latitude        = 13.048313, longitude = 80.226672;
   
    private MapView mapView;
    private MapController mapController;
    private GeoPoint geoPoint;



    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        mapView = (MapView) findViewById(R.id.mapview);

        //sets the zoom to see the location closer
        mapView.getController().setZoom(12);

        //this will let you to zoom in or out using the controllers
        mapView.setBuiltInZoomControls(true);

        List< Overlay > mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
        
        MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable, this);

        GeoPoint point = new GeoPoint((int) (latitude * 1000000), (int) (longitude * 1000000));
       
       //this will show you the map at the exact location you want (if you not set this you will see the map somewhere in America)
        mapView.getController().setCenter(point);
        OverlayItem overlayitem = new OverlayItem(point, "Title for dialog", "Alba Iulia City From Romania");
        GeoPoint point1 = new GeoPoint((int) (latitude * 1000000), (int) (longitude * 1000000));
        GeoPoint point2 = new GeoPoint(35410000, 139460000);
        OverlayItem overlayitem2 = new OverlayItem(point2, "Title for dialog", "Japan");
        OverlayItem overlayitem3 = new OverlayItem(point1, "Title for dialog", "Netgrow");

        itemizedoverlay.addOverlay(overlayitem);
        itemizedoverlay.addOverlay(overlayitem2);
        itemizedoverlay.addOverlay(overlayitem3);
        mapOverlays.add(itemizedoverlay);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

Screen shot :






Download source...

No comments:

Post a Comment