Thursday 15 January 2015

android - get the latitude and longitude of a clicked location on the map in osmdroid -


I detect an Android app that down user location shown on the map using a marker. Here is the relevant code:

  Implementation LocationList of public class main activity activity {see the public map map map; Personal Location Manager Location Manager; MyItemizedOverlay myItemizedOverlay = Faucet; Drawing marker; Crate on Public Zero (Bundle Saved Instantstate) {Super. Secret (Saved Instantstate); SetContentView (R.layout.activity_main); MapView = (MapView) this.findViewById (R.id.mapview); MapView.setUseDataConnection (wrong); MapView.setClickable (true); MapView.setBuiltInZoomControls (true); MapView.setMultiTouchControls (true); MapView.setUseDataConnection (wrong); MapView.setFocusable (true); MapView.setFocusableInTouchMode (true); MapView.getController () setZoom (16). // Set the initial zoom-level, the marker = you get the sign of your need (source). Int marker wide = 1; Int MarkerHyat = 1; Marker Setbound (0, markerHyight, markerwidth, 0); LocationManager = (LocationManager) getSystemService (event .LOCATION_SERVICE); LocationManager.requestLocationUpdates (LocationManager.GPS_PROVIDER, 0, 0, this); // You can also use LocationManager.GPS_PROVIDER and // LocationManager.PASSIVE_PROVIDER} @Override public void onLocationChanged (Location) {int lat = (int) (location.getLatitude () * 1E6); Int lng = (int) (location.getLongitude () * 1E6); Geographic point = New GeoPoint (latitude, LNG); MapView.getController () setCenter (dot). . MapView.getController () animateTo (point); MapView.invalidate (); Resource proxy resource proxy = new DefaultResourceProxyImpl (getApplicationContext ()); MyItemizedOverlay = New MyItemizedOverlay (Marker, Resource PROC); MapView.getOverlays () Clear () .; . Adding MapView.getOverlays () (myItemizedOverlay); MyItemizedOverlay.addItem (dot, "myPoint1", "myPoint1"); TextView tv1 = (TextView) findViewById (R.id.myLat); Tv1.setText ("Late" + Latitude); TextView tv2 = (TextView) findViewById (R.id.myLong); Tv2.setText ("Long" + LNG); } @Override public void onStatusChanged (String provider, int position, bundled extras) {} @Override public void onProviderEnabled (String provider) {} @Override public void onProviderDisabled (String provider) {}   < P>}  

Now I need a way to get the latitude and longitude properties of the location clicked on the map. I mean I need something similar to the following code in osmdroid (which is present for Google Map API).

  google.maps.event.addListener (map, function (event 'click',) {YourHandler (event.latLng);});    

You have to create an overlay and override <. Code> onSingleTapConfirmed

Try this:

  overlay touchOverlay = new overlay (this) {ItemizedIconOverlay & LT; OverlayItem & gt; Another imitem IconOverlay = null; @Override protected void draw (Canvas arg0, MapView ARG1, Boolean ARG2) {} @Override public boolean OnSingleTapConfirmed (Last MotionEvent E, last MapView MapView) {final Drawable marker = getApplicationContext (). GetResources () GetDrawable (R.drawable. Markericon); See projection projection = map view. Jiopoint Public = (Jiopoint) Projkfrem pixel ((Int) I.atiaks () (Int) Ikji.a.tikik ()); String longitude = double .string (((double) loc.getLongitudeE6 ()) / 1000000; String latitude = double. Toasting (((double) loc.getLatitudeE6 ()) / 1000000; System.out.println ("Latitude =" + Latitude + ", Longitude =" + Longitude "); ArrayList & quot; OverlayItem & gt; Overlays = New Array of Lieutenant & quot; Overlaytem> (); Overlayitam MapTime = New Overlayitum ("", new geographic (((double (double)) people .getLatitudeE6 ()) / 1000000, (((dual) loc.getLongitudeE6 ()) / 1000000)); mapItem.setMarker ( Marker); overlayArray.add (mapItem); if (anotherItemizedIconOverlay == faucet) {anotherItemizedIconOverlay = New ItemizedIconOverlay & lt; OverlayItem & gt; (getApplicationContext (), overlayArray, faucet); mapView.getOverlays () (anotherItemizedIconOverlay);; MapView.invalidate ();} and {mapView.getOverlays (). Remove (second IitemizedIconOverlay); ma PView.invalidate (); Another itemized IconOverlay = new itemNamed online overlay & lt; overlayem & gt; (getApplicationContext (), overlayare, blank); mapView.getOverlays () (anotherItemizedIconOverlay) add .;} // dlgThread (); True;}}; mapView.getOverlays () (touchOverlay);    

No comments:

Post a Comment