【问题标题】:How to render directions coordinates in react-native-maps using mapquest coordinates data?如何使用 mapquest 坐标数据在 react-native-maps 中呈现方向坐标?
【发布时间】:2020-08-19 13:36:52
【问题描述】:

我正在尝试使用 MapQuest REST API 中的坐标在地图上渲染方向折线,但我得到折线没有完全显示在道路顶部。相反,它显示了不同的输出。 我想准确地在道路顶部绘制折线。我正在发送以下请求以获取路线(使用 MapQuest Directions Route API):

http://www.mapquestapi.com/directions/v2/optimizedroute?key=[API_KEY]&json={%22locations%22:[%2234.0120337,-6.7383617%22,%2234.0253894,-6.7592364%22]}

然后根据上述请求会话 id,我正在发送另一个请求以获取坐标(使用 MapQuest Directions Route Shape API):

http://www.mapquestapi.com/directions/v2/routeshape?key=[API_KEY]&sessionId=[ABOVE_REQUEST_SESSION_ID]&mapWidth=320&mapHeight=240&mapScale=1733371&mapLat=34.0120337&mapLon=-6.7383617

我正在使用数组route.shape.shapePoints,我应该如何在地图上的道路上方正确绘制折线?

我正在使用的代码:

<MapView
    style={{ flex: 1 }}
    showsUserLocation
    initialRegion={{
        latitude,
        longitude,
        latitudeDelta: 0.0922,
        longitudeDelta: 0.0421
    }}
>
    <MapView.Polyline strokeWidth={2} strokeColor="red" coordinates={this.state.coords}></MapView.Polyline>
</MapView>

下面是我得到的当前地图的截图:

【问题讨论】:

    标签: android react-native openstreetmap react-native-maps mapquest


    【解决方案1】:

    尝试将泛化选项设置为较低的值,例如 0 或 10。

    【讨论】:

    • 谢谢,我确实将选项 generalize 设置为 Route Shape API 请求中的 url 参数,它起作用了。默认情况下不设置generalize时,它的-1不会返回所有形状点并使地图看起来像上面一样。
    猜你喜欢
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 2020-03-26
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    相关资源
    最近更新 更多