Skip to content

Instantly share code, notes, and snippets.

@laabroo
Created June 16, 2012 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laabroo/2940296 to your computer and use it in GitHub Desktop.
Save laabroo/2940296 to your computer and use it in GitHub Desktop.
Menapilkan posisi kita ke map
protected void tampilkanPosisikeMap(Location newLocation) {
List<Overlay> overlays = mapView.getOverlays();
if (overlays.size() > 0) {
for (Iterator<Overlay> iterator = overlays.iterator(); iterator
.hasNext();) {
iterator.next();
iterator.remove();
}
}
// transform the location to a geopoint
GeoPoint geopoint = new GeoPoint(
(int) (newLocation.getLatitude() * 1E6),
(int) (newLocation.getLongitude() * 1E6));
GeoPoint myposition = geopoint;
Location locationA = new Location("point A");
Location locationB = new Location("point B");
locationA.setLatitude(geopoint.getLatitudeE6() / 1E6);
locationA.setLongitude(geopoint.getLongitudeE6() / 1E6);
// initialize icon
Drawable icon = getResources().getDrawable(R.drawable.mappin);
icon.setBounds(0, 0, icon.getIntrinsicWidth(),
icon.getIntrinsicHeight());
// create my overlay and show it
MyItemizedOverlay overlay = new MyItemizedOverlay(icon, this);
OverlayItem item = new OverlayItem(geopoint, "Me", "Posisi saat ini.");
overlay.addItem(item);
mapView.getOverlays().add(overlay);
for (int i = 0; i < list_lokasi.size(); i++) {
geopoint = new GeoPoint((int) (list_lokasi.get(i).getLat() * 1E6),
(int) (list_lokasi.get(i).getLon() * 1E6));
locationB.setLatitude(geopoint.getLatitudeE6() / 1E6);
locationB.setLongitude(geopoint.getLongitudeE6() / 1E6);
icon = getResources().getDrawable(R.drawable.marker);
icon.setBounds(0, 0, icon.getIntrinsicWidth(),
icon.getIntrinsicHeight());
overlay = new MyItemizedOverlay(icon, this);
item = new OverlayItem(geopoint, list_lokasi.get(i).getName(),
"Posisi : " + list_lokasi.get(i).getAddress()
+ "\n Jarak : " + list_lokasi.get(i).getRad()
+ " km");
overlay.addItem(item);
Log.i("Jumlah : ", new String(String.valueOf(overlays.size())));
mapView.getOverlays().add(overlay);
}
// move to location
mapView.getController().animateTo(myposition);
mapView.getController().zoomIn();
mapView.getController().zoomOut();
// redraw map
mapView.postInvalidate();
}
@laabroo
Copy link
Author

laabroo commented Jun 16, 2012

Ini adalah cara gimana kita menampilkan posisi ke Map. Pada bari kode ke-29 itu berguna untuk menampilkan informasinya berupa object yang diterima pada saat icon pushpin merah (posisi kita) saat di tap. Dan pada bari kode ke-46 itu berguna untuk menampilkan informasinya berupa object yang diterima pada saat icon pushpin(kuning) di tap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment