【发布时间】:2018-05-01 13:33:51
【问题描述】:
我正在使用 (React-Native) 开发移动应用程序,基本上我目前正在处理的主要功能是:。
- 地图集成:部分成功 - 我成功完成了link 中提到的所有事情。剩下的事情是根据我从起点到终点的当前位置显示实时路线。
下面是我用来渲染视图的代码:
<View style={ styles.container }>
<MapView
initialRegion = {{
latitude: this.state.origin.latitude,
longitude: this.state.origin.longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA
}}
ref={(ref) => { this.mapRef = ref }}
onLayout = {() => this.mapRef.fitToCoordinates([{longitude: this.state.origin.longitude, latitude: this.state.origin.latitude}, {longitude: this.state.destination.longitude, latitude: this.state.destination.latitude}], { edgePadding: { top: 100, right: 10, bottom: 200, left: 10 }, animated: true })}
provider={ PROVIDER_GOOGLE }
style={ styles.map }
showsUserLocation={ true }
followsUserLocation={true}
loadingEnabled={true}
overlays={[{
coordinates: this.state.routeCoordinates,
strokeColor: '#19B5FE',
lineWidth: 10
}]}
>
<MapView.Marker
coordinate={ this.state.origin }
/>
<MapView.Marker
coordinate={ this.state.destination }
/>
<MapViewDirections
origin={this.state.origin}
destination={this.state.destination}
apikey={GOOGLE_MAPS_APIKEY}
strokeWidth={5}
strokeColor={'#000000'}
mode={'driving'}
onStart={(params) => {
console.log('Your journey has been started');
}}
onReady={(result) => {
console.log('Reach to the starting point to start journey');
}}
onError={(errorMessage) => {
alert(errorMessage);
}}
/>
</MapView>
<View style={styles.bottomBar}>
<View style={styles.bottomBarGroup}>
<Text style={styles.bottomBarHeader}>Directions</Text>
{this.state.directions.map((directionsObj, index) => (
<Text key={index} style={styles.bottomBarContent}>{directionsObj.html_instructions}
</Text>
))}
</View>
</View>
</View>
但是这段代码只显示了起点和终点之间的地图,我想显示起点和终点之间的实时导航。喜欢出租车预订应用程序。
【问题讨论】:
-
这个问题太宽泛了 - 请缩小您遇到问题的地图集成的特定方面(最好使用示例代码)。
-
@JoeClay 如何实现“基于我当前位置从起点到终点的实时路由”。我正在使用下面的模块来实现这一点。 npmjs.com/package/react-native-maps
-
@JoeClay 我想现在我的问题是针对这个问题的。
标签: javascript reactjs google-maps react-native ionic2