ios - iPhone 上的谷歌地图看起来与安卓不同
问题描述
我们正在开发一个与打字稿反应的网络应用程序。使用react-google-maps
包我们嵌入了谷歌地图。一切正常,除了地图没有按预期在 iPhone 上显示。我们已经使用过fitBounds
,但这在 iphone 上不起作用。这是代码。
import React, { useContext, useRef, useEffect } from 'react';
import { compose, withProps } from 'recompose';
import { withScriptjs, withGoogleMap, GoogleMap, Marker } from 'react-google-maps';
import env from '../../utils/env.utils';
import { compileGoogleMapsScriptSrc, silverMapDesign } from '../../utils/misc.utils';
import DrawingManager from 'react-google-maps/lib/components/drawing/DrawingManager';
import { ThemeContext } from 'styled-components';
import Boundry from './polygon';
import { BuildingLocation } from '../../state/tour/tour.types';
import images from '../../utils/img.utils';
const MapLocator = compose(
withProps({
googleMapURL: compileGoogleMapsScriptSrc(env.googleApiKey),
loadingElement: <div />,
containerElement: <div style={{ height: `100%`, width: `100%` }} />,
mapElement: <div style={{ height: `100%` }} />,
}),
withScriptjs,
withGoogleMap,
)(props => {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
// prettier-ignore
const { data, allData, center: location, zoomValue: zoom, marker, selected, selectAll, doneDrawing, allowEdit } = props;
const ref: any = useRef<HTMLElement>(null);
const { primary: primaryColor } = useContext(ThemeContext);
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const bounds = new window.google.maps.LatLngBounds();
data.forEach((coor: any) => {
const { lat, lng } = coor;
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const latLng = new window.google.maps.LatLng(lat, lng);
bounds.extend(latLng);
console.log(zoom);
ref.current?.fitBounds(bounds);
});
}, [data]);
return (
<GoogleMap
// defaultZoom={zoom}
defaultCenter={location}
defaultOptions={{ styles: silverMapDesign, streetViewControl: false }}
ref={ref}
>
{allData ? (
allData.map((ele: BuildingLocation[], index: number) => <Boundry data={ele} key={index} />)
) : (
<Boundry data={data} />
)}
{allowEdit && (
<DrawingManager
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
defaultDrawingMode={google.maps.drawing.OverlayType.POLYGON}
defaultOptions={{
drawingControl: true,
drawingControlOptions: {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
position: google.maps.ControlPosition.TOP_CENTER,
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
drawingModes: [google.maps.drawing.OverlayType.POLYGON],
},
polygonOptions: {
strokeColor: primaryColor,
strokeOpacity: 1,
strokeWeight: 4,
fillColor: 'rgba(6, 56, 231, 1)',
fillOpacity: 0.05,
},
}}
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
onPolygonComplete={doneDrawing}
/>
)}
{marker &&
marker.map((mark: Location, i: number) => {
return (
<Marker
position={mark}
key={i}
icon={selectAll || selected === i ? images.blueMapMarker : images.grayMapMarker}
zIndex={selected === i ? 200 : 100}
/>
);
})}
</GoogleMap>
);
});
export default MapLocator;
解决方案
推荐阅读
- javascript - Graphql - 有没有办法同时插入两个表,但第二个表依赖于第一个表的返回?
- selenium - selenium 中是否有任何功能可以在使用 java 不可见的字段中输入文本?
- java - org.springframework.web.bind.MissingServletRequestParameterException:必需的字符串参数“文本”不存在
- python - 保存显示 Plotly Express 小部件的 Jupyter Notebook
- mongodb - 查询mongodb数组的文档
- php - 在 PHP SQL 查询中使用“WHERE”的问题
- java - Android NFC 总是在应用关闭时调用 onCreate
- vb.net - VB.net - 我如何从网站获取响应数据?
- c# - 尝试使用 NPoco 在数据库中插入值时出错
- google-maps - 当应用程序在前台或后台反应原生时如何调用函数?