【问题标题】:Call getBounds() on MapView.Circle在 MapView.Circle 上调用 getBounds()
【发布时间】:2021-04-12 19:03:58
【问题描述】:

我想在 Map View.Circle 组件上从 Geolib 调用 getBounds(points) 函数。我不太确定,如何获取我的圆圈区域内的坐标列表。这样我就可以将它作为参数传递给 getBounds 函数。 我看到在响应谷歌地图等上调用来自谷歌地图 API 的 getBounds() 的帖子。但在这种情况下不确定。 下面是我的地图显示和圆形代码。请分享您的知识和建议。

<MapView style={styles.mapContainer} 
        region = {{latitude: region.latitude,
              longitude: region.longitude,
              latitudeDelta: region.latitudeDelta,
              longitudeDelta: region.longitudeDelta}}
        >
        <MapView.Marker
            coordinate={{
            latitude: region.latitude,
            longitude:region.longitude}}
            title={"Me"}
         />
         <MapView.Circle
                key = { (region.latitude + region.longitude).toString() }
                center = {pickedLocation}
                radius = { 100 }
                strokeWidth = { 2 }
                strokeColor = { '#1a66ff' }
                fillColor = { 'rgba(230,238,255,0.5)' }
        />
        </MapView>

【问题讨论】:

    标签: javascript reactjs react-native google-maps expo


    【解决方案1】:

    可能使用 geolib 并这样做

    import { getBoundsOfDistance } from 'geolib';
    const cordinates = getBoundsOfDistance({latitude: number, longitude: number}, radius);
    mapRef.current?.fitToCoordinates(cordinates, {
                    edgePadding: {
                        top: 20,
                        right: 20,
                        bottom: 20,
                        left: 20,
                    },
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-29
      • 2012-07-20
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多