首页 > 解决方案 > error navigate with react-native-open-maps

问题描述

i tried to navigate to my maps in my phone (googleMap or iphoneMaps) with react-native-open-maps but when it opens the map it doesnt show me the specific place and i cant navigate to this place. if anyone can help me how to navigate to a specific location i will be greatful

import createOpenLink from 'react-native-open-maps';

<MapView
                    style={{ flex: 0.8, width: Dimensions.get('window').width }}
                    region={{
                        latitude: currentElement.coordinates.latitude,
                        longitude: currentElement.coordinates.longitude,
                        latitudeDelta: 0.122,
                        longitudeDelta: 0.121,
                    }} >
                    <Marker
                        onPress={() => openYosemiteZoomedOut(currentElement.coordinates.latitude,currentElement.coordinates.longitude)}
                        coordinate={{
                            latitude: currentElement.coordinates.latitude,
                            longitude: currentElement.coordinates.longitude,
                        }}
                    />
                </MapView>
const openYosemiteZoomedOut =(lat,long)=>{ createOpenLink({latitude:lat,longitude:long,zoom:30 });}

标签: react-nativemaps

解决方案


使用此代码而不是使用库

 if (Platform.OS === 'android') {
          Linking.openURL(`geo:0,0?q=${latitude},${longitude}(${info})`)
    .catch(err => console.error('An error occurred', err));
        } else {
          Linking.openURL(`http://maps.apple.com/?ll=${latitude},${longitude}&q=${info}`)
    .catch(err => console.error('An error occurred', err));
        }

推荐阅读