Marker in gmaps android

Assalamu alaikum wr.wb.
Sedikit share soal cara membuat marker di android bagi teman2 yang masih bingung ok kita bingung sama2. ini ada sample code curian dari link http://www.mobiforge.com/developing/story/using-google-maps-android
langsung kita coba aja ya.. hehehehe😀 karna berhubung aq baca di fb masih blom bisa make ya terpaksa aq ulang tulis deg.. josssssssss. langsung code yo :😀

package com.laabroo.android.andropeta;

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 MainActivity extends MapActivity {
MapView myMap;
MapController mc;
GeoPoint p;

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

myMap = (MapView) findViewById(R.id.myMap);
LinearLayout zoom = (LinearLayout) findViewById(R.id.layout);
View zoomView = myMap.getZoomControls();

zoom.addView(zoomView, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
myMap.displayZoomControls(true);
// mapView.setSatellite(true);
myMap.setStreetView(true);
myMap.setTraffic(true);

mc = myMap.getController();
String coordinates[] = { "-7.795006", "110.387567" };
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(25);

// ---Add a location marker---
MapOverlay mapOverlay = new MapOverlay();
List listOfOverlays = myMap.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
myMap.invalidate();

}

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

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s