我试图使用react-native地图在android设备上的当前用户地理位置上渲染地图.
这是到目前为止我得到的:
import React, { Component } from 'react';import { VIEw, StyleSheet, Dimensions,} from 'react-native';import MapVIEw from 'react-native-maps';const {wIDth, height} = Dimensions.get('window')const SCREEN_HEIGHT = heightconst SCREEN_WIDTH = wIDthconst ASPECT_RATIO = wIDth / heightconst LATITUDE_DELTA = 0.0922const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIOclass MapComponent extends Component { constructor() { super() this.state = { initialposition: { latitude: 0, longitude: 0, latitudeDelta: 0, longitudeDelta: 0, }, } } componentDIDMount() { navigator.geolocation.getCurrentposition((position) => { var lat = parsefloat(position.coords.latitude) var long = parsefloat(position.coords.longitude) var initialRegion = { latitude: lat, longitude: long, latitudeDelta: LATITUDE_DELTA, longitudeDelta: LONGITUDE_DELTA, } this.setState({initialposition: initialRegion}) }, (error) => alert(JsON.stringify(error)), {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}); } renderScreen = () => { return ( <VIEw style={styles.container}> <MapVIEw style={styles.map} initialRegion={this.state.initialposition}/> </VIEw> ); } render() { return ( this.renderScreen() ); }}const styles = StyleSheet.create({ container: { position: 'absolute', top: 0, @R_419_6823@: 0, right: 0, bottom: 0, justifyContent: 'flex-end', alignItems: 'center', }, map: { position: 'absolute', top: 0, @R_419_6823@: 0, right: 0, bottom: 0, },});export default MapComponent;
地图将按预期方式渲染,但不会在当前设备地理位置中渲染. (它渲染在大海中间)
权限已在AndroIDManifest.xml中设置为:
<uses-permission androID:name="androID.permission.ACCESS_FINE_LOCATION" />
20秒后,我收到警报,提示“位置请求超时”“代码3”
我做错了什么?
解决方法:
我不确定,但是有一个issue (“Geolocation timed out, code 3”)看起来很相关
总结For anyone else struggling with this issue on androID, try removing
the maximumAge: 2000 option parameter. This option was causing
geolocation to either timeout or crash the app.
以上是内存溢出为你收集整理的android-如何使用react-native-maps获取当前位置全部内容,希望文章能够帮你解决android-如何使用react-native-maps获取当前位置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)