reactjs - 谷歌地图 Img 标签 React Native
问题描述
我目前正在使用 google Api,似乎我的地图由于某种原因被阻止了。我在 API 中使用了一个代码,但我不明白为什么我不能在地图中移动,它是静态的(就像在代码中它保留在图像中一样)。我想知道如何继续以便能够在地图内移动并同时显示我的位置,提前感谢您的帮助。
这是我的代码
import React from 'react';
import { TouchableOpacity, Image, StyleSheet } from 'react-native';
import MapView from 'react-native-maps'
import ENV from '../env';
const MapPreview = props => {
let imagePreviewUrl;
if (props.location) {
imagePreviewUrl = `https://maps.googleapis.com/maps/api/staticmap?center=${
props.location.lat
},${
props.location.lng
}&zoom=2&size=200x200&maptype=roadmap&markers=color:red%7Clabel:A%7C${
props.location.lat
},${props.location.lng}&key=${ENV.googleApiKey}`;
}
return (
<TouchableOpacity onPress={props.onPress} style={{ ...styles.mapPreview, ...props.style }}>
{props.location ? (
<Image style={styles.mapImage} source={{ uri: imagePreviewUrl }} />
) : (
props.children
)}
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
mapPreview: {
justifyContent: 'center',
},
mapImage: {
width: '100%',
height: '100%'
}
});
export default MapPreview;
这是我得到的图片:这里
解决方案
尝试增加您在 So 上使用的缩放参数,imagePreviewUrl
而不是这个:
imagePreviewUrl = `https://maps.googleapis.com/maps/api/staticmap?center=${
props.location.lat
},${
props.location.lng
}&zoom=2&size=200x200&maptype=roadmap&markers=color:red%7Clabel:A%7C${
props.location.lat
},${props.location.lng}&key=${ENV.googleApiKey}`;
将缩放从 2 增加到 15:
imagePreviewUrl = `https://maps.googleapis.com/maps/api/staticmap?center=${
props.location.lat
},${
props.location.lng
}&zoom=15&size=200x200&maptype=roadmap&markers=color:red%7Clabel:A%7C${
props.location.lat
},${props.location.lng}&key=${ENV.googleApiKey}`;
希望这可以帮助!
推荐阅读
- scala - 用自己的编解码器包装 circe 解码器(隐式)
- matlab - 不符合 3-d 矩阵和向量的参数
- java - 使用 feignclient 访问 HTTPS url 时的证书路径问题
- database-design - 如何设计数据库模式来存储文章某些部分的评论?
- powershell - 过滤/删除 CSV 文件的最后一列
- angular - 角度迁移(从 4 到 6)警告 - 无法解析流
- c# - Xamarin.Forms.Mac 命令未调用
- android - 如何在内部存储中为其他使用 android 的应用程序公开共享文件?
- javascript - Angular 6 从 HTMLTemplateElement 创建 HTMLElement
- android - 使用 IMASDK、android 暂停广告?