Отсутствует маркер в API Карт Google React Geolocation - PullRequest
1 голос
/ 20 марта 2019

Привет! Я использую следующий код в своем приложении React, чтобы показать текущее местоположение. Но мне не хватает маркера, который показывает точное местоположение. Что мне не хватает? Геолокация поднимает карту, которая показывает область, но не маркер. Как добавить маркер?

import React from 'react';
import { GoogleApiWrapper, Map } from "google-maps-react";

export class MapContainer extends React.Component {
  state = { userLocation: { lat: 32, lng: 32 }, loading: true };

  componentDidMount(props) {
    navigator.geolocation.getCurrentPosition(
      position => {
        const { latitude, longitude } = position.coords;

        this.setState({
          userLocation: { lat: latitude, lng: longitude },
          loading: false,

        });
      },
      () => {
        this.setState({ loading: false });
      }
    );
  }

  render() {
    const { loading, userLocation } = this.state;
    const { google } = this.props;

    if (loading) {
      return null;
    }

    return <Map google={google} initialCenter={userLocation} zoom={15} />;

  }
}

export default GoogleApiWrapper({
  apiKey: "API_KEY"
})(MapContainer);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...