反应原生。我找不到我当前的位置(地理位置)IOS



我需要从GPS访问我的位置。因此,我将地理位置导入项目。

首先,我这样创建了这样的关注(安装反应本机映射,已经链接)

我只是在我的xcode

中添加了nslocationwheninuseusagedescription

另外,我只是在我的xcode

中aigrctGeoLocation.a

然后,我只是从Airbnb中读取MapView中的地图视图。告诉我设置ShowusLocation将其设置为" True"。设置时,将要求用户访问位置。

参考:https://github.com/airbnb/react-native-maps/blob/master/master/docs/mapview.md

最后,这不是要求任何访问的东西地点。所以,我不知道为什么。我找不到我当前的位置。

这是我从开始的逐步描述的我的图片https://i.stack.imgur.com/c7vik.jpg

我将向您展示我的代码。

rout.js

import React, { Component, PropTypes } from 'react';
import {
    StyleSheet,
    View,
    Text,
    Image,
    Dimensions,
} from 'react-native';
import MapView from 'react-native-maps';
var {height, width} = Dimensions.get('window');
export default class Route extends Component {
    constructor(props){
    super(props);
    this.state = {
        region: {
            latitude: 37.78825,
            longitude: -122.4324,
            latitudeDelta: 0.0922,
            longitudeDelta: 0.0421,
        }
    };
    this.onRegionChange = this.onRegionChange.bind(this);
}
onRegionChange(region) {
    this.setState({ region });
}
    render() {
        return (
            <View style={styles.container}>
        <MapView style={styles.map}
          mapType="standard"
          showsUserLocation={true}
          followsUserLocation={true}
          showsCompass={false}
          showsPointOfInterest={false}
          region={this.state.region}
          onRegionChange={this.onRegionChange}
        />
        <View style={styles.container}>
          <Text>
          Latitude: {this.state.region.latitude}{'n'}
          Longitude: {this.state.region.longitude}{'n'}
          LatitudeDelta: {this.state.region.latitudeDelta}{'n'}
          LongitudeDelta: {this.state.region.longitudeDelta}
          </Text>
        </View>
      </View>
        );
    }
}

Route.navigationOptions = { //this define from App.js option in SecondScreen
  title: 'Route', //name top of StackNavigator
};


const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
    },
    image: {
        width: 200,
        height: 200,
    },
    text: {
        color: 'white',
        fontWeight: 'bold',
        backgroundColor: 'transparent',
        marginTop: 20,
    },
    map: {
    width: width,
    height: height*2/3
  }
});

在iOS模拟器中,它读取一个假位置。使用 debug>位置>自定义位置... 在模拟器菜单中设置自定义位置。

如果您在真实设备上运行它,则将获得真实位置。如果继续使用模拟器,则可以使用自定义位置菜单放置当前位置。您可以以多种方式获取您的位置,包括以下方式:http://mylocation.org/。

最新更新