【问题标题】:@react-google-maps Marker LatLng throwing error@react-google-maps Marker LatLng 抛出错误
【发布时间】: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)

【问题讨论】:

    标签: reactjs react-google-maps


    【解决方案1】:

    位置属性是一个对象。像这样传递您的 lat 和 lng 值:

    
    <Marker position={{lat: 51.510228, lng: -0.132992}}></Marker>
    
    

    【讨论】:

      猜你喜欢
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 1970-01-01
      • 2013-01-24
      • 2017-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多