我正在使用@react-google-maps/api来构建我的第一个react地图。但是我在Marker中的位置的latLng文字破坏了我的代码。这是不是和我在center上使用的latLng格式一样好用呢?我的标记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)发布于 2020-07-13 16:15:16
position属性是一个对象。像这样传递您的lat和lng值:
<Marker position={{lat: 51.510228, lng: -0.132992}}></Marker>https://stackoverflow.com/questions/62871704
复制相似问题