question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] You have included the Google Maps API multiple times on this page. This may cause unexpected errors.

See original GitHub issue

I’m using a basic example and the script is added each time, I don’t know if this is the intended behaviour or am I missing something.

This is my component:

import React from "react"
import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps"

const Map =  withScriptjs(withGoogleMap((props) =>
  <GoogleMap
    defaultZoom={17}
    defaultCenter={{lat: 24.828797, lng: -107.441531}}
    center={props.location}
    defaultOptions={{ disableDefaultUI: true, gestureHandling: 'none' }}
  >
    {props.isMarkerShown && <Marker position={props.location} />}
  </GoogleMap>
))

export default Map

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:11
  • Comments:33

github_iconTop GitHub Comments

33reactions
karkbcommented, Oct 26, 2018

If you are having a script for google maps in your html element, then removing withScriptjs will solve the issue.

from Step 3: “If you don’t use withScriptjs, you have to put a <script/> tag for Google Maps JavaScript API v3 in your HTML’s <head/> element”

24reactions
ermikcommented, Jun 3, 2018

This can be solved by separating the compose() call that creates the render environment and the layout functional component like so:

const API_KEY = "aHR0cHM6Ly95b3V0dS5iZS9kUXc0dzlXZ1hjUQ=="

const mapEnvironment = compose(
  withProps({
    googleMapURL: `https://maps.googleapis.com/maps/api/js?key=${API_KEY}&v=3.exp&libraries=geometry,drawing,places`,
    loadingElement: <div style={{ height: `100%` }} />,
    containerElement: <div style={{ height: `400px` }} />,
    mapElement: <div style={{ height: `100%` }} />
  }),
  withScriptjs,
  withGoogleMap
);

const MapLayout = props => (
  <GoogleMap defaultZoom={8} defaultCenter={{ lat: -34.397, lng: 150.644 }}>
    {props.isMarkerShown && (
      <Marker position={{ lat: -34.397, lng: 150.644 }} />
    )}
  </GoogleMap>
);

const MapComponent = mapEnvironment(MapLayout);
Read more comments on GitHub >

github_iconTop Results From Across the Web

"You have included the Google Maps API multiple times on ...
I'm getting the error "You have included the Google Maps API multiple times on this page. This may cause unexpected errors." I know...
Read more >
You have included the Google Maps JavaScript API multiple ...
Got a problem with this You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors...
Read more >
You have included the Google Maps API multiple times on this ...
You have included the Google Maps API multiple times on this page. This may cause unexpected errors. · Diagnosis: Duplicate Google Maps API....
Read more >
You have included the Google Maps API multiple times on this ...
In the console it prints: "You have included the Google Maps API multiple times on this page. This may cause unexpected errors." "Google...
Read more >
Fix: Google Maps JavaScript API Multiple Times On This Page ...
An error can be shown in the console when you are using JavaScript API multiple times on your page, that says: "You have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found