Skip to content

Instantly share code, notes, and snippets.

@omayib
Created November 24, 2012 03:07
Show Gist options
  • Save omayib/4138209 to your computer and use it in GitHub Desktop.
Save omayib/4138209 to your computer and use it in GitHub Desktop.
Menampilkan overlay diatas map
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.map.marker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" >
</uses-permission>
<application
android:icon="@drawable/marker"
android:label="@string/app_name" >
<activity
android:name=".MapMarker"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
package com.map.marker;
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 CustomOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;
public CustomOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
}
public CustomOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mapOverlays.get(i);
}
@Override
public int size() {
// TODO Auto-generated method stub
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
AlertDialog.Builder ad = new AlertDialog.Builder(context);
ad.setTitle(item.getTitle());
ad.setMessage(item.getSnippet());
ad.show();
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
this.populate();
}
}
package com.map.marker;
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.OverlayItem;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
public class MapMarker extends MapActivity {
private MapView mapView;
private static final int latitude1 = -7824269;
private static final int longitude1 = 110364532;
private static final int latitude2 = -7822269;
private static final int longitude2 = 110424532;
/** 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.map_view);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
GeoPoint point = new GeoPoint(latitude1, longitude1);
GeoPoint point2 = new GeoPoint(latitude2, longitude2);
OverlayItem overlayitem = new OverlayItem(point, "Hai..", "Saya omayib");
OverlayItem overlayitem2 = new OverlayItem(point2, "Hai..",
"Saya Fitri");
CustomOverlay itemizedOverlay = new CustomOverlay(drawable, this);
itemizedOverlay.addOverlay(overlayitem);
itemizedOverlay.addOverlay(overlayitem2);
mapOverlays.add(itemizedOverlay);
MapController mapController = mapView.getController();
mapController.animateTo(point2);
mapController.setZoom(15);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment