如何解决React-Native Google Direction API无法正常工作
我正在开发一个移动应用程序,我的目标是在地图上显示两个人之间的距离,为此我使用了Google Direction api,但是存在问题。两个位置之间的距离线不可见。我在这里留下了map.js代码和警告。
代码:
import React,{Component} from 'react';
import {View,Text} from 'react-native';
import MapView from 'react-native-maps';
import MapViewDirections from 'react-native-maps-directions';
export default class Map extends Component{
state={
region:{
latitude: 37.78825,longitude: -122.4324,latitudeDelta: 0.015,longitudeDelta: 0.0121,}
}
componentWillMount(){
console.log(this.props.data);
const {yourLongLat}=this.props.data;
this.setState({
region:{
latitude: yourLongLat[0],longitude: yourLongLat[1],latitudeDelta: 6,longitudeDelta: 6,}
}
)
}
render(){
const {yourLongLat,herLongLat}=this.props.data;
const origin = {latitude: yourLongLat[0],longitude: yourLongLat[1]};
const destination = {latitude:herLongLat[0],longitude: herLongLat[1]};
const GOOGLE_MAPS_APIKEY = 'don't show api keys';
return(
<View style={{flex:1,backgroundColor:'green'}}>
<MapView
style={{flex:1}}
region={this.state.region}>
<MapViewDirections
origin={origin}
destination={destination}
apikey={GOOGLE_MAPS_APIKEY}
strokeWidth={6}
strokeColor="hotpink"
/>
</MapView>
</View>
)
}
}
İmages: enter image description here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。