如何在android中显示两个位置之间的路由?
我正在使用这个URL如何在android中显示两个位置之间的路由?,android,google-maps,Android,Google Maps,我正在使用这个URL http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f 显示两点之间的方向页面。 我想知道我可以向这个URL添加什么来获得两点之间的路由 目前,它是显示方向页第一,当我按下路线标签,使它显示路线页,但我想它应该直接转到路线页 我正在使用这个代码 String new_url = "http://maps.google.com/maps?saddr=" + ServerData.LATTITUDE + "," + S
http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f
显示两点之间的方向页面。
我想知道我可以向这个URL添加什么来获得两点之间的路由
目前,它是显示方向页第一,当我按下路线标签,使它显示路线页,但我想它应该直接转到路线页
我正在使用这个代码
String new_url = "http://maps.google.com/maps?saddr=" + ServerData.LATTITUDE + "," + ServerData.LONGITUDE + "&daddr=" + latitude + "," + longitude ;
Intent intent_map = new Intent(Intent.ACTION_VIEW, Uri.parse(new_url));
startActivity(intent_map);
请帮助尝试以下代码。下面的代码将返回纬度和经度位置列表。由此,您必须使用画布为最近的点绘制直线。下面的代码还有一个可以使用的位置标记字符串列表
private ArrayList<String> getDirectionData(String srcPlace, String destPlace) {
String urlString = "http://maps.google.com/maps?f=d&hl=en&saddr="
+ srcPlace + "&daddr=" + destPlace
+ "&ie=UTF8&0&om=0&output=kml";
Log.d("URL", urlString);
Document doc = null;
HttpURLConnection urlConnection = null;
URL url = null;
ArrayList<String> pathConent = new ArrayList<String>();
try {
url = new URL(urlString.toString());
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(urlConnection.getInputStream());
} catch (Exception e) {
}
NodeList nl = doc.getElementsByTagName("LineString");
for (int s = 0; s < nl.getLength(); s++) {
Node rootNode = nl.item(s);
NodeList configItems = rootNode.getChildNodes();
for (int x = 0; x < configItems.getLength(); x++) {
Node lineStringNode = configItems.item(x);
NodeList path = lineStringNode.getChildNodes();
pathConent.add(path.item(0).getNodeValue());
}
}
placeMarks=new ArrayList<String>();
NodeList place=doc.getElementsByTagName("Placemark");
for(int i=0;i<place.getLength();i++){
Node root=place.item(i);
NodeList config=root.getChildNodes();
Node placenode=config.item(0);
NodeList name=placenode.getChildNodes();
placeMarks.add(name.item(0).getNodeValue());
Log.i("Node Value: ", ""+name.item(0).getNodeValue());
}
placeMarks.remove((placeMarks.size()-1));
Log.i("LineString: ", pathConent.get(0));
ArrayList<String> tmpcoords=new ArrayList<String>();
for(int i=0;i<pathConent.size();i++){
tmpcoords.addAll(Arrays.asList(pathConent.get(i).split(" ")));
}
//String[] tempContent = pathConent.split(" ");
return tmpcoords;
}
试试下面的代码。下面的代码将返回纬度和经度位置列表。由此,您必须使用画布为最近的点绘制直线。下面的代码还有一个可以使用的位置标记字符串列表
private ArrayList<String> getDirectionData(String srcPlace, String destPlace) {
String urlString = "http://maps.google.com/maps?f=d&hl=en&saddr="
+ srcPlace + "&daddr=" + destPlace
+ "&ie=UTF8&0&om=0&output=kml";
Log.d("URL", urlString);
Document doc = null;
HttpURLConnection urlConnection = null;
URL url = null;
ArrayList<String> pathConent = new ArrayList<String>();
try {
url = new URL(urlString.toString());
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(urlConnection.getInputStream());
} catch (Exception e) {
}
NodeList nl = doc.getElementsByTagName("LineString");
for (int s = 0; s < nl.getLength(); s++) {
Node rootNode = nl.item(s);
NodeList configItems = rootNode.getChildNodes();
for (int x = 0; x < configItems.getLength(); x++) {
Node lineStringNode = configItems.item(x);
NodeList path = lineStringNode.getChildNodes();
pathConent.add(path.item(0).getNodeValue());
}
}
placeMarks=new ArrayList<String>();
NodeList place=doc.getElementsByTagName("Placemark");
for(int i=0;i<place.getLength();i++){
Node root=place.item(i);
NodeList config=root.getChildNodes();
Node placenode=config.item(0);
NodeList name=placenode.getChildNodes();
placeMarks.add(name.item(0).getNodeValue());
Log.i("Node Value: ", ""+name.item(0).getNodeValue());
}
placeMarks.remove((placeMarks.size()-1));
Log.i("LineString: ", pathConent.get(0));
ArrayList<String> tmpcoords=new ArrayList<String>();
for(int i=0;i<pathConent.size();i++){
tmpcoords.addAll(Arrays.asList(pathConent.get(i).split(" ")));
}
//String[] tempContent = pathConent.split(" ");
return tmpcoords;
}
Android支持访问内部应用程序及其称为Android内部地图活动的最佳解决方案,以显示两个地理点之间的路线。请参考下面的代码
String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
它称为内置地图活动,并在当前和固定纬度和经度之间绘制路线路径。Android支持访问内部应用程序及其称为Android内部地图活动的最佳解决方案,以显示两个地理点之间的路线。请参考下面的代码
String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
它调用内置地图活动,并在当前和固定纬度和经度之间绘制路径。您可以通过在Android中打开默认的Android地图活动来完成相同的操作 您可以查看以下示例代码: 例如网址:`
https://maps.google.com/maps?saddr=28.61000000,77.23000000&daddr=28.98000000,77.02000000
String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+destLatitude+","+destLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
附截图
您也可以在Android中打开默认的Android地图活动 您可以查看以下示例代码: 例如网址:`
https://maps.google.com/maps?saddr=28.61000000,77.23000000&daddr=28.98000000,77.02000000
String uri = "http://maps.google.com/maps?saddr=" + currentLatitude+","+currentLongitude+"&daddr="+destLatitude+","+destLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
附截图
检查此问题:检查Max Gontar的回答:我可以在此kml url中传递多个lat和long吗?仅通过一些点进行示例检查此问题:检查Max Gontar的回答:我可以在此kml url中传递多个lat和long吗?仅通过一些点进行示例