React -Native“经度值不能从字符串转换为双精度”

Hec*_*888 2 reactjs react-native react-native-maps

我正在使用react-native-maps并且使用此代码得到纬度和经度:

callLocation(that) {
  navigator.geolocation.getCurrentPosition(
    position => {
      const currentLongitude = JSON.stringify(position.coords.longitude);
      const currentLatitude = JSON.stringify(position.coords.latitude);
      that.setState({ currentLongitude: currentLongitude });
      that.setState({ currentLatitude: currentLatitude });
    },
    error => alert(error.message),
    { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
  );
  that.watchID = navigator.geolocation.watchPosition(position => {
    console.log(position);
    const currentLongitude = JSON.stringify(position.coords.longitude);
    const currentLatitude = JSON.stringify(position.coords.latitude);
    that.setState({ currentLongitude: currentLongitude });
    that.setState({ currentLatitude: currentLatitude });
  });
}
Run Code Online (Sandbox Code Playgroud)

这是我的地图视图代码:

<MapView
  style={styles.map}
  initialRegion={{
    latitude: this.state.currentLatitude,
    longitude: this.state.currentLongitude,
    latitudeDelta: 0.0922,
    longitudeDelta: 0.0421
  }}
/>
Run Code Online (Sandbox Code Playgroud)

当我将这个纬度和经度粘贴到我的代码中时,出现以下错误:

MUS*_*SSI 5

没有什么比像这样解析坐标位置更容易的了:

{
   latitude: parseFloat(myObj.latitude),
   longitude: parseFloat(myObj.longitude)
}
Run Code Online (Sandbox Code Playgroud)