【发布时间】:2021-03-21 06:23:43
【问题描述】:
我正在使用 Windows 在 android studio 上处理地理定位代码。但由于某种原因,我现在的位置没有被选中。我尝试使用其他选项,例如 enableHighAccuracy:false。还尝试运行 Telnet,并应用 geo fix long lat,但没有任何反应。
请查看我在博览会零食上测试时实际工作的相关代码。
findCurrentLocationAsync=()=>{
navigator.geolocation.getCurrentPosition(
(position) => {
// console.log(position);
let lat=position.coords.latitude;
let long=position.coords.longitude;
this.setState({
markerPosition: {
lat: lat,
lng: long
},
mapPosition: {
latitude: lat,
longitude: long,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}
});
Geocoder.from( this.state.mapPosition.latitude , this.state.mapPosition.longitude ).then(
response => {
const address = response.results[0].formatted_address,
addressArray = response.results[0].address_components,
city = this.getCity( addressArray ),
area = this.getArea( addressArray ),
state = this.getState( addressArray );
zip = this.getZip( addressArray );
console.log(addressArray)
this.setState( {
address: ( address ) ? address : '',
area: ( area ) ? area : '',
city: ( city ) ? city : '',
state: ( state ) ? state : '',
zip: ( zip ) ? zip : '',
} )
},
error => {
// console.error( error );
}
)
},
//{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 },
///()=>console.log(lat)
);
};
非常感谢您的建议
谢谢 萨尔
【问题讨论】:
-
也发布有关代码。
-
请检查。代码有效。但不选择当前位置。刚刚粘贴了相关代码。谢谢
-
您使用了 expo-location。但我认为它更多的是andorid问题。你看到使用 navigator.geolocation.getCurrentPosition 的问题了吗?
标签: javascript reactjs react-native android-studio react-redux