sya*_*rul 4 google-maps-api-3 react-native
是否可以在不完全依赖浏览器 DOM 的情况下使用 javascript api 来渲染地图,因为 react-native 使用 View 我觉得可以以某种方式使用 api,通过传递给全局窗口使 api 可用的方法也可以使用 fetch,但我不知道如何启动回调。如果有人知道这是如何工作的,请分享一些想法
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
Run Code Online (Sandbox Code Playgroud)
提到的googlemaps节点模块@sunilp只为您提供静态地图,无需依赖lib即可轻松构建,只需搜索google maps api静态地图(没有足够的声誉发布两个以上的链接)。
对于 Android,你有这个:https : //github.com/teamrota/react-native-gmaps
对于 iOS,有这个,但它警告说这是一项正在进行的工作(几个月也没有更新):https : //github.com/peterprokop/ReactNativeGoogleMaps
环顾四周,如果您搜索他们的文档,似乎您今天对 iOS 的最佳(支持)选择是使用 React Native 自己的 MapView。然后,您可以为数据对 Google Maps API 服务进行 fetch 调用,然后通过其接口填充 MapView。确保您传入您的密钥并在您的 url 中使用 https 否则服务将拒绝您的呼叫:
fetch(
'https://maps.googleapis.com/maps/api/directions/json?origin=41.13694,-73.359778&destination=41.13546,-73.35997&mode=driver&sensor=true&key=[YOUR_KEY]'
)
.then(
(response) => response.text()
)
.then(
(responseText) => {
console.log(responseText);
}
)
.catch(
(error) => {
console.warn(error);
}
);
`
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9121 次 |
| 最近记录: |