>假设我有一条从A地到B地的路线,1,2,3分别是我的自行车停顿。我希望人们唯一搜索路线,他将能够看到搜索路线之间的可用停靠点。
搜索查询将:来源:A,目的地:B
输出:[在地图视图中]显示A 到 B的路线和停靠点 1,2,3,其中 1,2,3有自己的纬度和经度
我使用谷歌地图来实现这样的功能,片段如下
PolylineOptions mPolylineOptions = new PolylineOptions();
.......
ArrayList<LatLong> latLngs = ....// list of route polypoints to draw path
mPolylineOptions.addAll(latLngs).width(10).color(polylineColor);
mMap.addPolyline(mPolylineOptions);
mMap.addMarker(new MarkerOptions().position(stopPoint1).flat(true).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_car)));
mMap.addMarker(new MarkerOptions().position(stopPoint2).flat(true).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_car)));
mMap.addMarker(new MarkerOptions().position(stopPoint3).flat(true).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_car)));
使用必应地图 SDK 也很容易做到这一点:
// Create layer to add your collection of map elements MapElementLayer mapLayer = new MapElementLayer(); // Create geo path with the route points ArrayList<Geoposition> positions = new ArrayList<Geoposition>(); positions.add(new Geoposition(routePoint1.getLatitude(), routePoint1.getLongitude())); positions.add(new Geoposition(routePoint2.getLatitude(), routePoint2.getLongitude())); ... positions.add(new Geoposition(routePointN.getLatitude(), routePointN.getLongitude())); // Create and add route polyline to the map layer. MapPolyline route = new MapPolyline(); route.setPath(new Geopath(positions)); mapLayer.getElements().add(route); // Create and add stop icons to the map layer. MapIcon stop1 = new MapIcon(); stop1.setLocation(new Geopoint(stopPoint1.getLatitude(), routePoint1.getLongitude())); mapLayer.getElements().add(stop1); ... // Add layer to display map elements in the map control mapView.getLayers().add(mapLayer);
如果需要 Web 控件,请注意,交互式 SDK 中也有用于折线、图钉和向图层添加多个项目的示例。