【发布时间】:2020-11-02 09:41:38
【问题描述】:
我正在使用@react-google-maps/api 构建我的第一个反应图。但是我在Marker 中的位置的 latLng 文字破坏了我的代码。这与我用于center 的 latLng 格式不一样吗?我的 Marker latLng 怎么错了?这似乎是docs 中唯一需要的属性,所以我走上了死胡同。
import React, { Component } from 'react';
import { GoogleMap, LoadScript, Marker } from '@react-google-maps/api';
import icon1 from '../map/icon1.svg';
import iconDead from '../map/iconDead.svg';
const center = { lat: 51.510228, lng: -0.132992 };
const API = 'xxxx';
const containerStyle = {
width: '100%',
height: '800px'
};
function MyComponent( markers, onToggleOpen ) {
return (
<LoadScript
googleMapsApiKey={API}
>
<GoogleMap
mapContainerStyle={containerStyle}
center={center}
zoom={10}
>
<Marker position={ lat: 51.510228, lng: -0.132992 }></Marker>
<></>
</GoogleMap>
</LoadScript>
)
}
export default React.memo(MyComponent)
【问题讨论】: