如何在react-native映射上获取中心坐标?

pho*_*ong 3 dictionary ios react-native

我正在使用react-native.如何在iOS地图上获取中心坐标?

小智 10

来自:https://facebook.github.io/react-native/docs/mapview.html#content

region {latitude:number,longitude:number,latitudeDelta:number,longitudeDelta:number}

要由地图显示的区域.

该区域由中心坐标和要显示的坐标范围定义.

因此,您可以使用地图的region属性获取中心坐标,使用类似的方法

getCoordinates(region) {
    return [{
      longitude: region.longitude,
      latitude: region.latitude,
    }];
},
Run Code Online (Sandbox Code Playgroud)

如果需要传递一个全局变量getCoordinates,可以使用一个全局变量,该变量随着各种状态变化设置的新值而变化onRegionChange.