Created
June 16, 2012 06:58
-
-
Save laabroo/2940296 to your computer and use it in GitHub Desktop.
Menapilkan posisi kita ke map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.