Sie es verwenden können, um es wie Google vergessen nicht den Internet-Erlaubnis
String getDistanceOnRoad(double latitude, double longitude,
double prelatitute, double prelongitude) {
String result_in_kms = "";
String url = "http://maps.google.com/maps/api/directions/xml? origin="
+ latitude + "," + longitude + "&destination=" + prelatitute
+ "," + prelongitude + "&mode=driving&sensor=false&units=metric";
String tag[] = { "text" };
HttpResponse response = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
response = httpClient.execute(httpPost, localContext);
InputStream is = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = builder.parse(is);
if (doc != null) {
NodeList nl;
ArrayList<String> args = new ArrayList<String>();
for (String s : tag) {
nl = doc.getElementsByTagName(s);
if (nl.getLength() > 0) {
Node node = nl.item(nl.getLength() - 1);
args.add(node.getTextContent());
} else {
args.add(" - ");
}
}
result_in_kms = String.format("%s", args.get(0));
}
} catch (Exception e) {
e.printStackTrace();
}
return result_in_kms;
}
diese Bibliothek Klasse hinzufügen Zeit, Distanz und ziehen Linienzug zwischen zwei Orten es wie google map arbeiten zu bekommen https://github.com/memo1231014/MUT-master
Beispiel für die Bibliothek
RouteInformations rInformation = new RouteInformations(new AsyncResponse() {
@Override
public void processFinish(RouteDetails arg0) {
// TODO Auto-generated method stub
try
{
map.addPolyline(arg0.getLineOptions()); //you can add the return line and add it to the map
//here you can get distance , duration it will return like you drive a car
MUT.fastDialog(Map.this,"Time and Distance","Distance : "+arg0.getDistance()+"\nDuration : "+arg0.getDuration());
}
catch(Exception e)
{
MUT.lToast(Map.this,"Can't draw line Try Again");
}
}
});
//you should pass the 2 lat and lang which you want to draw a aline or get distance or duration between them
RouteDetails routeDetails=new RouteDetails();
routeDetails.setLatLong1(from.getPosition());
routeDetails.setLatLong2(to.getPosition());
rInformation.execute(routeDetails);
tun Sie gerade Linie Abstand wollen, oder Sie Oberflächenabstand wollen (arc, curve)? – gian1200
was meinst du mit genauer entfernung? –