我如何在React Native Mapview中设置标记

时间:2019-03-13 07:33:14

标签: javascript reactjs google-maps react-native react-native-maps

我正在使用Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim Mail As Outlook.MailItem If TypeOf Item Is Outlook.MailItem Then Set Mail = Item If Mail.Subject = "sample" Then Mail.DeferredDeliveryTime = GetNextWeekday(vbMonday) & " 08:00 AM" End If End If End Sub Private Function GetNextWeekday(ByVal DayOfWeek As VbDayOfWeek) As Date Dim diff As Long diff = DayOfWeek - Weekday(Date, vbSunday) If diff > 0 Then GetNextWeekday = DateAdd("d", diff, Date) Else GetNextWeekday = DateAdd("d", 7 + diff, Date) End If End Function ,同时显示了地图和当前   纬度和经度,但我不知道如何在地图上显示纬度和经度的标记。

经纬度代码:

react-native-maps

地图代码:

callLocation(that){
navigator.geolocation.getCurrentPosition(
   (position) => {
      const currentLongitude = position.coords.longitude;
      const currentLatitude = position.coords.latitude;
      that.setState({ currentLongitude:currentLongitude });
      that.setState({ currentLatitude:currentLatitude });
   },
   (error) => alert(error.message),
   { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
that.watchID = navigator.geolocation.watchPosition((position) => {
    console.log(position);
    const currentLongitude = position.coords.longitude;
    const currentLatitude =  position.coords.latitude;
   that.setState({ currentLongitude:currentLongitude });
   that.setState({ currentLatitude:currentLatitude });
});}

2 个答案:

答案 0 :(得分:0)

您应该使用Marker组件。

示例:

import { MapView, Marker } from 'react-native-maps';

<MapView
  style={styles.map}
  initialRegion={{
    latitude:  this.state.currentLatitude,
    longitude: this.state.currentLongitude,
    latitudeDelta: 0.0922,
    longitudeDelta: 0.0421,
  }}
>
  <Marker
    coordinate={{latitude: 40.741075, longitude: 74.0003317}}
    title={'title'}
    description={'description'}
  />
</MapView>

答案 1 :(得分:0)

工作示例:

<MapView provider={Platform.OS === 'android' ? PROVIDER_GOOGLE : PROVIDER_DEFAULT}  // remove if not using Google Maps
 style={{width: '100%', height: FULL_SH*0.51, marginTop: 65*SH}}
  initialRegion={{
     latitude: this.state.myLat ? this.state.myLat : 38.4555,
     longitude: this.state.myLon ? this.state.myLon : 27.1199,
     latitudeDelta: 0.015,
     longitudeDelta: 0.0121}}>
    <MapView.Marker
       coordinate={{latitude: 38.4555, longitude: 27.1199}}
       title={'Deneme'}
     />
    <MapView.Marker
       onPress={() => this.setState({visible: true}) + setTimeout(() => alert(this.state.visible), 200)}
       description={'güzel mekan'}
       coordinate={{latitude: 38.4555, longitude: 27.1129}}
       title={'Deneme'}/>
</MapView>