Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to measure area from current location to another location using GPS coordinates in android
    primarykey
    data
    text
    <p>I am developing an application in Android Tablet,i got a new requirement that i need to find out the distance between one point to other selected point can any one please help me how to achieve this</p> <p>I found that in google maps we have one option called Measure in Labs menu i need same kind of requirement can any one tell me how to invoke/implement programatically measured feature in Google maps.</p> <p>Please check the below image for better understanding.</p> <p>Waiting for your valuable inputs...<img src="https://i.stack.imgur.com/l6mSv.jpg" alt="enter image description here"></p> <p>I am using below code for showing current gps location now i need to know how to point other location and draw line and then measure area please check my code and suggest me</p> <pre><code>public class Tracking extends MapActivity implements LocationListener { LocationManager locman; LocationListener loclis; Location Location; private MapView map; List&lt;GeoPoint&gt; geoPointsArray = new ArrayList&lt;GeoPoint&gt;(); private MapController controller; String provider = LocationManager.GPS_PROVIDER; double lat; double lon; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initMapView(); initMyLocation(); locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE); //locman.requestLocationUpdates(provider,60000, 100,loclis); //Location = locman.getLastKnownLocation(provider); } /** Find and initialize the map view. */ private void initMapView() { map = (MapView) findViewById(R.id.mapView); controller = map.getController(); map.setSatellite(false); map.setBuiltInZoomControls(true); } /** Find Current Position on Map. */ private void initMyLocation() { final MyLocationOverlay overlay = new MyLocationOverlay(this, map); overlay.enableMyLocation(); overlay.enableCompass(); // does not work in emulator overlay.runOnFirstFix(new Runnable() { public void run() { // Zoom in to current location controller.setZoom(24); controller.animateTo(overlay.getMyLocation()); } }); map.getOverlays().add(overlay); } @Override public void onLocationChanged(Location location) { if (Location != null){ lat = Location.getLatitude(); lon = Location.getLongitude(); GeoPoint New_geopoint = new GeoPoint((int)(lat*1e6),(int)(lon*1e6)); controller.animateTo(New_geopoint); geoPointsArray.add(New_geopoint); } } public double getDistance(double lat1, double lon1, double lat2, double lon2) { double latA = Math.toRadians(lat1); double lonA = Math.toRadians(lon1); double latB = Math.toRadians(lat2); double lonB = Math.toRadians(lon2); double cosAng = (Math.cos(latA) * Math.cos(latB) * Math.cos(lonB-lonA)) + (Math.sin(latA) * Math.sin(latB)); double ang = Math.acos(cosAng); double dist = ang *6371; return dist; } class MyOverlay extends Overlay{ public MyOverlay(){ } public void draw(Canvas canvas, MapView mapv, boolean shadow){ super.draw(canvas, mapv, shadow); Projection projection = map.getProjection(); Path p = new Path(); for (int i = 0; i &lt; geoPointsArray.size(); i++) { if (i == geoPointsArray.size() - 1) { break; } Point from = new Point(); Point to = new Point(); projection.toPixels(geoPointsArray.get(i), from); projection.toPixels(geoPointsArray.get(i + 1), to); p.moveTo(from.x, from.y); p.lineTo(to.x, to.y); } Paint mPaint = new Paint(); mPaint.setStyle(Style.STROKE); mPaint.setColor(0xFFFF0000); mPaint.setAntiAlias(true); canvas.drawLine(0, 4,5,50, mPaint); canvas.drawPath(p, mPaint); super.draw(canvas, map, shadow); } } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } @Override public void onStatusChanged(String arg0, int arg1, Bundle arg2) { // TODO Auto-generated method stub }} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload