gpt4 book ai didi

ios - react-native-maps fitToSuppliedMarker/fitToCorodinates 不显示所有标记

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:28:49 28 4
gpt4 key购买 nike

我正在尝试使用简单的 MapView 并显示 2 个标记。

它们都在 map View 中正确显示,但在屏幕上不能同时显示(默认情况下呈现 Image1)

我必须执行手动拖动操作才能在屏幕上看到两个标记。(我手动拖动 map 以便在屏幕上看到它们之后的图 2)

我尝试使用 fitToSuppliedMarkers/fitToCocordinates,但似乎没有任何效果。

export default class FavItemMapView extends Component{

constructor(props){
super(props)
this.state={
position:{
latitude:1.286353,
longitude:103.853067,
latitudeDelta: 0,
longitudeDelta: 0,
},
error:null
}
this.mapRef = null;
}

componentWillMount(){

const favPlaceLatitude = parseFloat(this.props.navigation.state.params.latitude)
const favPlaceLongitude = parseFloat(this.props.navigation.state.params.longitude)
markers.push({latitude:favPlaceLatitude,longitude:favPlaceLongitude});
navigator.geolocation.getCurrentPosition(
(position) => {
console.log("wokeeey" + width + height);
console.log(position);
var lat = parseFloat(position.coords.latitude)
var long = parseFloat(position.coords.longitude)

var initialRegion = {
latitude: lat,
longitude: long,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}

this.onRegionChange(initialRegion)
},
(error) => this.setState({ error: error.message }),
{ enableHighAccuracy: false, timeout: 200000, maximumAge: 1000 },
);
}

onRegionChange(region) {
this.setState({ position:region })
}

componentDidMount(){
//this.mapRef.fitToSuppliedMarkers(markerIDs,true);
const favPlaceLatitude = parseFloat(this.props.navigation.state.params.latitude)
const favPlaceLongitude = parseFloat(this.props.navigation.state.params.longitude)
this.mapRef.fitToCoordinates([{latitude:favPlaceLatitude,longitude:favPlaceLongitude}], {
edgePadding: {
bottom: 200, right: 50, top: 150, left: 50,
},
animated: true,
});
}

render(){

const { navigation } = this.props;
const favPlaceLatitude = parseFloat(navigation.state.params.latitude)
const favPlaceLongitude = parseFloat(navigation.state.params.longitude)

return(
<View style={styles.container}>
<MapView provider={MapView.PROVIDER_GOOGLE} ref={ref => {this.mapRef = ref;}} style={styles.map} region={this.state.position}>
{this.state.position.latitude &&
<MapView.Marker identifier="Marker2" coordinate={{latitude:this.state.position.latitude,longitude:this.state.position.longitude}} pinColor="red"/>
}
{this.state.position.longitude &&
<MapView.Marker identifier="Marker1" coordinate={{latitude:favPlaceLatitude,longitude:favPlaceLongitude}} pinColor="green"/>
}
</MapView>
</View>
);
}
}

const styles={
container:{
...StyleSheet.absoluteFillObject,
justifyContent: 'flex-end',
alignItems: 'center',
},
map:{
padding:100,
...StyleSheet.absoluteFillObject
}
}

你能告诉我哪里出了问题吗?附加模拟器图像以供引用。 enter image description here enter image description here

最佳答案

<MapView
provider={MapView.PROVIDER_GOOGLE}
ref={map => {this.map = map}}
style={{ flex: 1 }}
initialRegion={{latitude:this.state.request.latitude,
longitude:this.state.request.longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,}}
onMapReady={() => {this.map.fitToSuppliedMarkers(['mk1','mk2'],{ edgePadding:
{top: 50,
right: 50,
bottom: 50,
left: 50}

})}}
>
<Marker
image={require('../../../assets/pin.png')}
coordinate={{latitude:this.state.request.latitude,longitude:this.state.request.longitude}}
title='Punto de partida'
identifier={'mk1'}
>

</Marker>

<Marker
image={require('../../../assets/pin_final.png')}
coordinate={{latitude:this.state.request.latitude_destinity,longitude:this.state.request.longitude_destinity}}
title='Punto de destino'
identifier={'mk2'}
>

关于ios - react-native-maps fitToSuppliedMarker/fitToCorodinates 不显示所有标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52856815/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com