为什么React Native Maps不显示我的用户位置?

问题描述 投票:-2回答:2

完全莫名其妙。

我实现了React Native Maps。我将showsUserLocation道具设置为true。在IOS / Xcode中,我将键/值添加到info.plist

<key>NSLocationWhenInUseUsageDescription</key>
    <string>a description lives here and stuff</string>

通过添加.gpx文件,我能够模拟用户位置。

但是在Android中我无法获取showsUserLocation,showsMyLocationButton,showsCompass道具才能工作。

是否有模拟器或An / Studio中的设置允许这样做?

MapView类:

<MapView
    provider={PROVIDER_GOOGLE}
    followsUserLocation={true}
    showsUserLocation={true}
    showsMyLocationButton={true}
    showsCompass={true}
    toolbarEnabled={true}
    zoomEnabled={true}
    rotateEnabled={true}

    style={{flex: 1}}
    region={{
    latitude: 51.4718,
    longitude: -0.0749,
    latitudeDelta: 0.01,
    longitudeDelta: 0.01
    }}
>
    { markers.map((each, i) => {
        console.log('each: ', each);
        return ( 
            <MapView.Marker
                key={i}
                title={each.title}
                description={each.description}
                coordinate={{ latitude: each.latitude, longitude: each.longitude }}
                />
        )
    }) }
</MapView>

我也试图给IOS模拟器lat / lng,但Debug> Location> Custom Location让我编辑Lat或Long。不是都。很奇怪。

android react-native react-native-maps
2个回答
0
投票

我在Android中遇到了同样的问题。所以,我做了一个自定义的showUserlocation。我在哪里做了一个按钮

              <View >
                    <TouchableOpacity onPress={() => this.find_me()} >
                        <Image style={{ width: 30, height: 30 }} 
                            source={require('../resources/img/icon_pin_dark.png')} />

                    </TouchableOpacity>
                </View>

渲染这个功能。

find_me() {

        this.show = true
        navigator.geolocation.getCurrentPosition((position) => {

            this.region = {
                latitude: position.coords.latitude,
                longitude: position.coords.longitude,
                latitudeDelta: LATITUDE_DELTA,
                longitudeDelta: LONGITUDE_DELTA
            }
            this.userLocation = {
                latitude: position.coords.latitude,
                longitude: position.coords.longitude
            }
          
            console.log('yeah')
          

          

        }, 
        (error) => {
           
            console.log("Location provider is not enable")
        },
        
        )
    }

0
投票
    _onMapReady = () => this.setState({marginBottom: 0})

.........

<MapView
    style={{flex: 1, marginBottom: this.state.marginBottom}}
    onMapReady={this._onMapReady}

你的初始保证金底部应为1。

这对我很好。

© www.soinside.com 2019 - 2025. All rights reserved.