我在项目的expo中使用MapView时遇到问题。在EXPO应用程序中,iOS和Android都可以正常运行,但是在将同一应用程序构建并发布到Android apk时,无论是在游戏商店中还是在打开地图时注意,应用程序都会崩溃并重新加载。
我正在使用:
这里是代码:
import MapView, { Marker, Callout, CalloutSubview } from 'react-native-maps';
<MapView
ref={'map'}
onPress={() => this._mapPress()}
provider={PROVIDER_GOOGLE}
style={styles.mapView}
initialRegion={{
latitude: mapLat,
longitude: mapLon,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
>
{markers.map((marker, i) => (
<Marker
key={`marker-${i}`}
coordinate={marker.latlng}
stopPropagation={true}
onPress={e => this._mapMarkerPress(marker)}
>
<Image
resizeMode='cover'
source={
JSON.stringify(this.state.selectedMarker) == JSON.stringify(marker)
? ACTIVE_PIN
: INACTIVE_PIN
}
style={styles.mapMarker}
/>
</Marker>
))}
</MapView>
起初,我认为markers数组或初始lat long存在问题,但是删除部分代码后,我将MapView缩小为:
<MapView
ref={'map'}
provider={PROVIDER_GOOGLE}
>
</MapView>
并且仍然无法在apk / live Android上运行,但是在ios live中可以正常工作,显示一个空的地图。但是无论是在ios还是android博览会应用中,无论有没有标记,一切都很好。
有人遇到这个问题吗?谢谢!
尝试添加markerLat
和markerLon
参数并替换为:
initialRegion={{
latitude: mapLat,
longitude: mapLon,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
带有此:
initialRegion={{
latitude: mapLat,
longitude: mapLon,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
},
markerLat: Number(48.736279),
markerLon: Number(19.146191)
}