2017-02-21 93 views
0

我需要從GPS訪問我的位置。所以,我將地理位置導入到項目中。反應原生。我找不到我目前的位置(地理位置)IOS

首先,我創建下面這個樣子(安裝反應本地地圖,已經鏈接)

,我只是已經在我的Xcode我在Xcode中添加NSLocationWhenInUseUsageDescription

也是,我剛已經libRCTGeolocation.a

然後,我剛剛閱讀Airbnb的mapview地圖視圖。告訴我設置showUserLocation將其設置爲「true」。當設置爲true時將要求用戶訪問 位置。

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

最後,不問什麼訪問 位置。所以,我不知道爲什麼。我找不到我目前的位置。

,這是我的照片一步步,我從開始描述 http://imgur.com/a/5TJZa

我會告訴你我的代碼。

Route.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 
    } 
}); 
+0

在iOS模擬器中,它讀取一個假的位置。在仿真器菜單中使用_Debug> Location> Custom Location ..._設置自定義位置。 – bendman

+0

但我需要從GPS獲取當前位置。我該怎麼辦? –

+0

如果您在真實設備上運行它,您將獲得真實位置。否則,您可以將您當前的位置放在我之前評論中提到的菜單中。您可以通過多種方式獲得您的位置,包括:https://mylocation.org/ – bendman

回答

0

在iPhone模擬器它讀取一個假位置。在模擬器菜單中使用調試>位置>自定義位置...設置自定義位置。

如果您在真實設備上運行它,您將獲得真實位置。如果您繼續使用模擬器,則可以使用自定義位置菜單來放置當前位置。您可以通過多種方式獲取您的位置,其中包括:​​。