Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"You have included the Google Maps API multiple times on this page" Error

I have the following in my html page:

    <script type="text/javascript"
            src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">
    </script>
    <script 
        async defer
        src="https://maps.googleapis.com/maps/api/js?key=hUnDAdjYG_Wz7u2qL6unHqfBOmvaZ0H1Mg&callback=initMap">
    </script>

First link is for Google's API Geometry Library , and the second initialises and draws the map.

I'm getting the error "You have included the Google Maps API multiple times on this page. This may cause unexpected errors."

I know that this can be fixed by calling just one script, and changing the parameters, see Fixing "You have included the Google Maps API multiple times on this page. This may cause unexpected errors." I don't know how to replicate the answer for my problem though.

like image 603
MRDJR97 Avatar asked Jul 07 '17 11:07

MRDJR97


People also ask

What is the daily limit for Google Maps API?

While there is no maximum number of requests per day, the following usage limits are in place for the Maps JavaScript API: 30,000 requests per minute. 300 requests per minute per IP address. In the Google Cloud Console, this quota is referred to as Map loads per minute per user.

Is Google Maps API no longer free?

Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).


2 Answers

You can include one link:

<script type="text/javascript"
        src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false&key=AIzaSyBSsKUzYG_Wz7u2qL6unHqfBOmvaZ0H1Mg&callback=initMap">
</script>

Basically merging the url parameters in both the links.

like image 188
dhaliman Avatar answered Nov 14 '22 23:11

dhaliman


Had the same problem that disturbed me for long time. My case was to combine initMap to load map and Google Places API to list autocomplete to the input search.

Here is my solution to this.

  1. The function for autocomplete I've put inside the initMap()
function activatePlacesSearch() {

var input = document.getElementById('inputValue');
    var autocomplete = new google.maps.places.Autocomplete(input);
}
activatePlacesSearch();
  1. in index.html:
src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&libraries=places&callback=initMap"></script>

So best solution is to:

a) combine two scripts into one

b) place sensro functionality insite the initMap if possible.

like image 27
Magda Avatar answered Nov 14 '22 23:11

Magda