Question

Good afternoon. I have the following code

           ParseQuery query = new ParseQuery("MyOb");
    query.findInBackground(new FindCallback() {
       public void done(List<ParseObject> myOb, ParseException e) {
         if (e == null) { 
            for ( i = 0; i < myOb.size(); i++) {

            geo1Dub = myOb.get(i).getParseGeoPoint("location").getLatitude();
                geo2Dub = myOb.get(i).getParseGeoPoint("location").getLongitude();
                geo1Int = (int) (geo1Dub*1E6);
            geo2Int = (int) (geo2Dub*1E6);
            pointGet = new GeoPoint(geo1Int, geo2Int);           

                    OverlayItem overlayitem = new OverlayItem(pointGet, title, title);               
            itemizedoverlay.addOverlay(overlayitem);                                 

                  } 

            mapOverlays.add(itemizedoverlay);
            mapView.postInvalidate();
          } else {


         }
       }
     });

From the site, I am taking the points and display them on the map. Please tell me how can I use the

distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results)

to show the point that with me. My position will be at the point

 point = new GeoPoint(geoLat.intValue(), geoLng.intValue());
Was it helpful?

Solution

Distance Between two geo points:-

public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
            Double EARTH_RADIUS = 6371.00; 
            double earthRadius = EARTH_RADIUS;
            double dLat = Math.toRadians(lat2-lat1);
            double dLng = Math.toRadians(lng2-lng1);

            double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                    Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
                    Math.sin(dLng/2) * Math.sin(dLng/2);
            double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
            double dist = earthRadius * c;
            return new Float(dist).floatValue();
        }

OTHER TIPS

Create Location objects from GeoPointsand you have distanceTO() method.

http://developer.android.com/reference/android/location/Location.html

float distance[] = 0.0f;
double lat = Double.valueOf(point.getLatitudeE6()/1E6);
double lat = Double.valueOf(point.getLongitudeE6()/1E6);
Location.distanceBetween(geo1Dub, geo2Dub, lat, lng, distance);

You will have distance in meters in variable distance[0]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top