1

I am doing an Android project that takes the input as source and destination latitudes and longitudes, and adds a marker in exactly half the distance of the of the route.

For doing this, I get the distance of the route with this code:

public double CalculationByDistance(GeoPoint StartP, GeoPoint EndP) {
int Radius=6371;//radius of earth in Km         
double lat1 = StartP.getLatitudeE6()/1E6;
double lat2 = EndP.getLatitudeE6()/1E6;
double lon1 = StartP.getLongitudeE6()/1E6;
double lon2 = EndP.getLongitudeE6()/1E6;
double dLat = Math.toRadians(lat2-lat1);
double dLon = Math.toRadians(lon2-lon1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
double c = 2 * Math.asin(Math.sqrt(a));
double valueResult= Radius*c;
double km=valueResult/1;
DecimalFormat newFormat = new DecimalFormat("####");
kmInDec =  Integer.valueOf(newFormat.format(km));
meter=valueResult%1000;
meterInDec= Integer.valueOf(newFormat.format(meter));
Log.i("Radius Value",""+valueResult+"   KM  "+kmInDec+" Meter   "+meterInDec);
return Radius * c;
}

Can I use the Interpolate method of the SphericalUtil class to add the marker, or is there any easier way to do it?

Note: I cannot use Javascript as a part of my project. So please suggest a way of doing it in Android only! :D Thanks in advance! :D

mithun3010
  • 41
  • 7
  • is this for like a school assignment or a real-world thing? if it's a real world tool, you may want to change what you're doing to use the directions API stuff. you're calculating "as the crow flies" currently, which isn't really helpful to people travelling on roads. – jdu Mar 23 '15 at 18:54
  • check this answer maybe help you [Center a map marker in Android][1] [1]: http://stackoverflow.com/questions/17611544/center-a-map-marker-in-android – Hamza Alayed Mar 23 '15 at 18:54
  • @jdu - It is just a school assignment :) – mithun3010 Mar 23 '15 at 19:01
  • you have the length of the route so keep subtracting line segments until you find the middle – tyczj Mar 23 '15 at 19:04

0 Answers0