【发布时间】:2019-10-03 14:53:53
【问题描述】:
在这种情况下,当应用程序初始化时,Pin-marker 设置在当前位置,但在同一张地图中我有其他标记,当我尝试选择其他标记时,它再次适合当前位置,如何解决这个问题?我需要选择任何标记......并且......当我找到某个地方(带有谷歌位置)时,它会设置一个新标记并设置一个新位置并将相机设置为当前搜索标记并放大这个选定的标记,我的另一个问题是通过按钮获取当前位置(设备用户)的功能......有人可以帮助我吗???
<View style={styles.container}>
<StatusBar hidden />
<MapView
onPress={this.handleMapPress}
style={StyleSheet.absoluteFill}
ref={map => (this.mapView = map)}
rotateEnabled={true}
scrollEnabled={true}
showsMyLocationButton={true}
followsUserLocation={true}
showsUserLocation={true}
zoomEnabled={true}
showsPointsOfInterest={true}
showBuildings={false}
//region={this.props.region}
initialRegion={region}
provider="google">
{!!location && (
<MapView.Marker
coordinate={location}
onPress={this.handleMarkerPress}>
<Image
source={isAddressVisible ? placholder2 : placholder}
style={styles.icon}
/>
</MapView.Marker>
)}
{this.state.coordinates.map(
(coordinates, index, title, description, location) => (
<MapView.Marker
onPress={this.handleMapPress}
ref={mark => (coordinates.mark = mark)}
key={`coordinate_${index}`}
title={coordinates.title}
description={coordinates.description}
coordinate={{
latitude: coordinates.latitude,
longitude: coordinates.longitude,
}}>
<Image
source={isAddressVisible ? placholder2 : placholder}
style={styles.icon}
/>
</MapView.Marker>
)
)}
<MapView.Marker coordinate={this.props.region} >
<Image
source={ markerImage}
style={styles.icon}
/>
</MapView.Marker>
</MapView>
这里是调用当前位置的按钮:
<TouchableOpacity
onPress={this.getlocation}
style={styles.fab2}>
<Image
source={require('../assets/gps.png')}
style={{
width: 35,
height: 35,
margin: 10,
tintColor: 'white',
}}
/>
</TouchableOpacity>
【问题讨论】:
-
Hey i tried to reproduce this but can't, with the code provided in your previous thread the map is already centered and zoomed into the marker, and this occurs whenever a new place is selected so i don '不明白这个问题,您能否编辑您的问题以澄清目前究竟是什么不起作用?
-
嗨,Evan,我已经在 map-container.js 上粘贴了一个初始区域,以便直接在地图中打开。所以,现在我改变它,我把空白区域...地图,它再次更改为选定的 reg
-
如果我将
更改为 它允许我在地图上的其他区域中选择其他标记,但是当我搜索其他区域时,它不适合该区域的相机,只是标记 -
并将 region={this.props.region} 更改为 region={region}...
-
我试着制作一个按钮来移动到当前位置,但我做不到,我也需要帮助
标签: google-maps react-native google-maps-markers