如何根据 rgw 距离在 android 中沿一条线在 Google Maps 折线上添加标记?
Posted
技术标签:
【中文标题】如何根据 rgw 距离在 android 中沿一条线在 Google Maps 折线上添加标记?【英文标题】:How to add markers on Google Maps polylines based on rgw distance along a line in android? 【发布时间】:2019-08-21 05:07:33 【问题描述】:我在谷歌地图的两点之间画了一条线。现在我想在那条线上添加特定距离的标记。`
[![mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener()
@Override
public void onMapClick(LatLng latLng)
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latLng.latitude, latLng.longitude)).title("New Marker");
mMap.addMarker(marker).setDraggable(true);
mTempCollection.add(latLng);
mPolylineOptions.getPoints().clear();
mPolylineOptions.addAll(mTempCollection);
LatLngBounds latLngBounds = getPolygonCenterPoint(mTempCollection);
double distance = SphericalUtil.computeDistanceBetween(latLngBounds.southwest, latLngBounds.northeast);
Log.d(TAG, "distance: " + distance);
int plotmarkers = (int)(distance / 10);
mPolylineOptions.color(Color.GREEN);
mMap.addMarker(new MarkerOptions()
.position(latLngBounds.getCenter()));
mMap.addPolyline(mPolylineOptions);
);
` 在这一行中,我想添加特定距离的标记。
我发现这个链接在 javascript 中可以为 android 完成吗?How to add markers on Google Maps polylines based on distance along the line?
【问题讨论】:
看看***.com/questions/38497130/… 使用两个点 (SphericalUtil.computeHeading) 计算航向,然后使用航向、距离和原点 (SphericalUtil.computeOffset(from,distance,heading)) 计算偏移量,并在偏移量处添加标记。 【参考方案1】:如果你有两个标记,并且你想在离那条线起点一定距离的地方放置一个标记,你可以使用 SphericalUtil.interpolate 来完成这项工作。
double distance_between_points = SphericalUtil.computeDistanceBetween(startPointLoc, endPointLoc);
// 假设您希望新标记距离起点有 DISTANCE
LatLng newMarkerLoc = SphericalUtil.interpolate(startPointLoc, endPointLoc, (float) DISTNACE / distnace_between_points);
这里不是这样,你的距离可以是 1 公里、2 公里或任何你想要的(基于你提到的帖子)
【讨论】:
***.com/questions/38497130/…这个链接给了我答案,谢谢兄弟以上是关于如何根据 rgw 距离在 android 中沿一条线在 Google Maps 折线上添加标记?的主要内容,如果未能解决你的问题,请参考以下文章