【问题标题】:React Native maps get top left corner and bottom right corner latitude and longitudeReact Native 地图获取左上角和右下角纬度和经度
【发布时间】:2017-03-12 05:05:57
【问题描述】:

我正在开发一个使用 React-native-maps 的 react native 应用程序,目前我坚持获取当前区域的左上角(lat & long)和右下角(lat & long)

<MapView.Animated
        onRegionChange={this.onRegionChange.bind(this)}
        showsUserLocation
        initialRegion={{
          latitude: coords.latitude,
          longitude: coords.longitude,
          latitudeDelta: LATITUDE_DELTA,
          longitudeDelta: LONGITUDE_DELTA,
        }}
        style={{ flex: 1 }}
      >
      <MapView.Marker
          coordinate={{ latitude: coords.latitude, longitude: coords.longitude }}
      >
      <MapView.Callout style={{ position: 'relative', width: 150}}>
        <PlaceCard />
      </MapView.Callout>
    </MapView.Marker>
</MapView.Animated>

知道如何获得它吗?!

【问题讨论】:

    标签: react-native react-native-ios react-native-maps


    【解决方案1】:

    如果 (REGION.latitude, REGION.longitude) 是地图的中心,而增量是地图上显示的最小和最大纬度/经度之间的距离(以度为单位),那么您应该能够获得 topLeft和底部右点如下:

                {
                    latlng: {
                        latitude: REGION.latitude+(REGION.latitudeDelta/2),
                        longitude: REGION.longitude-(REGION.longitudeDelta/2)
                    },
                    title:'topLeft'
    
                },
                {
                    latlng: {
                        latitude: REGION.latitude-(REGION.latitudeDelta/2),
                        longitude: REGION.longitude+(REGION.longitudeDelta/2)
                    },
                    title:'bottomRight'
    
                }
    

    【讨论】:

    • 左上角还是右上角?还有右下角还是左下角?? ,我该如何计算增量?
    • 要计算增量,此链接可能很有用:github.com/airbnb/react-native-maps/issues/505。我用几个值(包括负值)测试了上面的响应,topLeft 和 bottomRight 的标记显示正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    相关资源
    最近更新 更多