我正在开发Android谷歌地图在我的论文中,我可以问一些关于Android的驾驶方向吗?Android谷歌地图驾驶方向
这是我的问题。
“如何在安卓谷歌地图中生成一个随机行驶方向,点击按钮时,它会随机给出从起点到终点的路径。”
谢谢!
我问谷歌地图通过这个。
private void parsing(GeoPoint start, GeoPoint end) throws ClientProtocolException, IOException, JSONException, URISyntaxException{
HttpClient httpclient = new DefaultHttpClient();
StringBuilder urlstring = new StringBuilder();
urlstring.append("https://maps.googleapis.com/maps/api/directions/json?origin=")
.append(Double.toString((double)start.getLatitudeE6()/1E6)).append(",").append(Double.toString((double)start.getLongitudeE6()/1E6)).append("&destination=")
.append(Double.toString((double)end.getLatitudeE6()/1E6)).append(",").append(Double.toString((double)end.getLongitudeE6()/1E6))
.append("&sensor=false");
//urlstring.append("http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=true");
url = new URI(urlstring.toString());
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = null;
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = "0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
reader.close();
String result = sb.toString();
JSONObject jsonObject = new JSONObject(result);
JSONArray routeArray = jsonObject.getJSONArray("routes");
JSONObject routes = routeArray.getJSONObject(0);
JSONObject overviewPolylines = routes.getJSONObject("overview_polyline");
String encodedString = overviewPolylines.getString("points");
List<GeoPoint> pointToDraw = decodePoly(encodedString);
//Added line:
mv_mapview.getOverlays().add(new RoutePathOverlay(pointToDraw));
}
在地图上点击。
class MapOverlay extends Overlay {
@Override
public boolean onTap(final GeoPoint p, MapView mapView) {
// TODO Auto-generated method stub
geop_Tpoint = p;
mcon_mapcontrol = mapView.getController();
mcon_mapcontrol.animateTo(p);
mv_mapview.invalidate();
longitude = (int)(p.getLongitudeE6()*1E6);
latitude = (int)(p.getLatitudeE6()*1E6);
new AlertDialog.Builder(ShowMap.this)
.setTitle("Routes")
.setMessage("Display Routes?")
.setNegativeButton("NO",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
textlocation.setText("Tap in the Map for Destination!");
dialog.dismiss();
}
})
.setPositiveButton("YES",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
try{
textlocation.setText("");
parsing(geop_startpoint,geop_Tpoint);
geocodeExecuter(geop_startpoint,geop_Tpoint);
showButton.setEnabled(true);
}catch(Exception e){
textlocation.setText(""+ e.getMessage());
}
}
}).show();
showButton.setEnabled(true);
return true;
}
的出发点是通过GPS,它会给我哪里IM一
这个问题太宽泛,请指定。你有什么尝试? – sschrass
对不起,对于我的语法感到遗憾..我的观点是,我有一个起点和一个终点。现在我的应用程序可以绘制一条路径,使用JSON从出发点到目的地点,我的问题是,如何改变具有相同点的路径?例如在Google map v3中,我可以拖动路径,但在我的我会用一个按钮来产生这种情况。 – HaTeRs