我有一个Android应用程序,我正在尝试用路由填充Google地图,该路由以这种方式存储在JSON数组中:
JSONArray.getString("points") = ["-33.45591917507404, -70.59198361376951","-33.453484420618416, -70.61635952929686"]所以在这种情况下,我有
Point A=(-33.49088437162095, -70.64043194102163)和
Point B=(-33.49423964397045, -70.63992768572683)我的路由或路径是A-B
我是Android的新手,我想知道如何让它工作。另外,在这种情况下,我的路由是A-B,但也可以是A-B-C-D。我可以在路径上有任意数量的点。
发布于 2012-10-24 10:57:56
您可以尝试使用Google Maps Polyline对象:您可以向setPath()指定一个有序的点列表(可以是LatLng数组,也可以是MVCArray或LatLng)的https://developers.google.com/maps/documentation/javascript/reference#Polyline,您希望在地图上连接在一起,Google Maps将根据您的规范为您创建一条polyline。
// path = Array of LatLng or MVCArray of LatLng
routeLine = new Polyline();
routeLine.setPath(JSONArray);在您的示例中,将JSONArray传递给setPath应该可以正常工作。
如果你想得到花哨的和合并的方向,你需要使用Google directions API。https://developers.google.com/maps/documentation/javascript/directions
// All waypoints must be stopovers for the Directions service to optimize their route.
// start & end are of type String or LatLng, waypts is an array of String or LatLng
request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: [type Boolean],
travelMode: [type TravelMode]
};
// go on and actually perform the request
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
// if successful, this will run
}
});一旦完成对象的构造,就应该能够通过运行setMap(map:Map)来显示它,例如
routeLine.setMap(map)https://stackoverflow.com/questions/13041270
复制相似问题