Javascript 如何在React Native的MapView中设置标记 我想在React Native的MapView上设置一个标记,但我无法通过的官方文档找到任何信息 如果不允许这样做,我如何使用现有的react模块,如react Native中的模块
根据,它还没有暴露出来。您也不能使用web React软件包,React Native不能这样工作 两项建议:Javascript 如何在React Native的MapView中设置标记 我想在React Native的MapView上设置一个标记,但我无法通过的官方文档找到任何信息 如果不允许这样做,我如何使用现有的react模块,如react Native中的模块,javascript,google-maps,reactjs,react-native,Javascript,Google Maps,Reactjs,React Native,根据,它还没有暴露出来。您也不能使用web React软件包,React Native不能这样工作 两项建议: 等待上述问题得到解决,以获得正确的API 尝试使用WebView链接到带有注释的Google地图 不过,我并不确定2是否可行。您可以使用 例如: var markers = [ { latitude: 45.65, longitude: -78.90, title: 'Foo Place', subtitle: '1234 Foo Drive'
不过,我并不确定2是否可行。您可以使用 例如:
var markers = [
{
latitude: 45.65,
longitude: -78.90,
title: 'Foo Place',
subtitle: '1234 Foo Drive'
}
];
<MapView
region={...}
annotations={markers}
/>
var标记=[
{
纬度:45.65,
经度:-78.90,
标题:"富坊",,
字幕:“1234富路”
}
];
谢谢@naoufal。
最后,我能够在地图上显示react本机IOS的标记
<View style={styles.container}>
<MapView style={styles.map}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0,
longitudeDelta: 0.0,
}}
>
<MapView.Marker
coordinate={{latitude: 37.78825,
longitude: -122.4324}}
title={"title"}
description={"description"}
/>
</MapView>
</View>
我提到了以下链接:
}))
“依赖项”:{
“本机基础”:“^2.13.8”,
“反应”:“16.9.0”,
“反应本机”:“0.61.2”,
“反应本机映射”:“git+”
},
import MapView,{Marker}来自“react native maps”;
谢谢@zia_qureshi。最后,我能够在地图上显示react原生android的标记。
从“react native maps”导入MapView,{Marker};
常量应用=()=>{
常量[region,setRegion]=useState({
纬度:51.5078788,
经度:-0.0877321,
纬度德尔塔:0.009,
纵向德尔塔:0.009
});
返回(
setRegion(region)}
>
);
};
导出默认应用程序代码>更新代码-2020 | React Native 0.63
import MapView, { Marker } from "react-native-maps";
<MapView
style={styles.mapStyle}
region={{
latitude: this.state.mapLat,
longitude: this.state.mapLong,
latitudeDelta: 0.001663,
longitudeDelta: 0.002001,
}}
onRegionChangeComplete={this.onRegionChange}
>
<Marker
coordinate={{latitude: 51.5078788, longitude: -0.0877321}}
>
</Marker>
</MapView>
从“react native maps”导入MapView,{Marker};
要求我们推荐或查找书籍、工具、软件库、教程或其他非网站资源的问题对于堆栈溢出来说是离题的,因为它们往往会吸引固执己见的答案和垃圾邮件。使用#2后,我认为最好的方法是#1。。。所以我会等待。谢谢~ MapView现在支持注释。我加了一个例子,谢谢你,@naoufal!我要试试看@ivanwang让我知道它是否适合你。如果是的话,你能把它标记为正确答案吗?@ Naoufal-任何关于这项工作在Android上的新闻吗?你可以通过<代码> <代码>作为<代码>儿童< /代码>,但是对于Android,但是PASASE做基本的设置来首先渲染地图。考虑解释你对问题的回答。owner@MuratAslan我不明白你的意思。你想让我解释答案吗?在代码添加之前,需要安装和配置(react native maps)
import MapView from 'react-native-maps';
<View style={StyleSheet.absoluteFillObject}>
<MapView style={styles.map}
showsUserLocation //to show user current location when given access
loadingEnabled //to show loading while map loading
style={styles.map}
initialRegion={{
latitude,
longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
{
locations && locations.map((location, index) => {
const {
coords: { latitude, longitude }
} = location;
return (
<MapView.Marker
key={index}
coordinate={{ latitude, longitude }}
title={"title"}
description={"address"}
// onPress={this.onMarkerPress(location)}
/>
)
})
}
</MapView>
</View>```
map: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}
Try using this. Hope it helps to mark for many locations. Happy Coding.
import MapView, { Marker } from 'react-native-maps';
<View>
<MapView
style={styles.mapStyle}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
<Marker coordinate = {{latitude: 37.78825,longitude: -122.4324}}
pinColor = {"purple"} // any color
title={"title"}
description={"description"}/>
</MapView>
</View>
import MapView, { Marker } from "react-native-maps";
<MapView
style={styles.mapStyle}
region={{
latitude: this.state.mapLat,
longitude: this.state.mapLong,
latitudeDelta: 0.001663,
longitudeDelta: 0.002001,
}}
onRegionChangeComplete={this.onRegionChange}
>
<Marker
coordinate={{latitude: 51.5078788, longitude: -0.0877321}}
>
</Marker>
</MapView>