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.

Issues loading places script for SearchField

See original GitHub issue

In the container my page component I’m loading the places script including my key and language.

const key = process.env.GOOGLE_API_KEY
    const language = 'NL'

    const placesUrl = `https://maps.google.com/maps/api/js?key=${ key }&language=${ language }libraries=places&sensor=false`

    load(placesUrl, { async: true }, (err, script) => {
      if (err) { console.log('error in load-script: ', err) }
      else { console.log('succes in load-script script.src: ', script.src) }
    })

Then in a child container I’m using the <GoogleMap />-tag feeding it only an options object and defaultCenter and defaultZoom. In my console I receive the following error:

You have included the Google Maps API multiple times on this page. This may cause unexpected errors. Google Maps API warning: NoApiKeys Google Maps API warning: SensorNotRequired

Also, I recieve an error for the searchField itself, copied from the searchbox example in readme:

Uncaught ReferenceError: google is not defined

Can I feed options and defaults in GoogleMap component, even after the script was already loaded? Is there a working example with the searchField included ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
istarkovcommented, Jun 1, 2017

@matmac the answer is directly above your comment, however if you just want to use places lib in other place without map

// bootstrapURLKeys.js
export const bootstrapURLKeys = {
  ...yourKeys,
  libraries: ['places'].join(','),
}

// places service.js 
import GoogleMapReact from 'google-map-react';
const { googleMapLoader } = GoogleMapReact;
import { bootstrapURLKeys } from './bootstrapURLKeys';
...
googleMapLoader(bootstrapURLKeys)
        .then((maps) => {
          const places = new maps.places.PlacesService(fakeElt);
          // use places
        }
...

// map.js
import { bootstrapURLKeys } from './bootstrapURLKeys';
...
<GoogleMap bootstrapURLKeys={bootstrapURLKeys}>
...
5reactions
istarkovcommented, Feb 15, 2017

The only way is to use custom loader which you can provide via googleMapLoader property, it must return Promise resolved to window.google.maps which google api defines at load.

Internally if nothing is provided this loader is used: https://github.com/istarkov/google-map-react/blob/master/src/utils/loaders/google_map_loader.js

So the idea is to return Promise which will be resolved only after third-party or your own google-map api will be loaded.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Places Search Box | Maps JavaScript API - Google Developers
This example creates a map with a search box for users to enter geographical searches. The search box returns a pick list that...
Read more >
bind google places autocomplete on textbox without ...
I'm having a problem with binding my search textbox with Autocomplete without the use of instantiating a google map. What I'm trying to...
Read more >
search field script - Claris Community - FileMaker Pro
I'm wanting to create a search find script for a field within a pop-up box. Is there a simple script that would allow...
Read more >
Cross Site Scripting (XSS) Attack Tutorial with Examples ...
If the search field is vulnerable, when the user enters any script, then it will be executed. Consider, a user enters a very...
Read more >
ACSD-45781: Store front search field not displayed on mobile ...
The MDVA-45781 patch solves the issue where the store front search field is not ... MDVA-28651: B2B - quotes slow to load ·...
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