user1229498
user1229498

Reputation: 323

Loading multiple maps libraries with javascript

I am trying to load both the maps library and the places library with javascript so I can embed a map into my page, use google.maps.geometry.spherical functions and make places search requests but I'm having trouble loading all 3 libraries. At the moment I am importing:

<script type="text/javascript"src="http://maps.google.com/maps?key=mykey"></script>
<script type="text/javascript"src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>

But I get the errors:

syntax error
[Break On This Error]   

...gs4d .gbmac,.gbes#gbg4 #gbgs4d .gbmac{margin:34px 0 0}.gbemi#gb #gbgs4d .gbmac,....

maps?k...hrkDAmw (line 1)

GClientGeocoder is not defined
[Break On This Error]   

var geocoder = new GClientGeocoder();

Where am I going wrong?

Thanks a lot.

Upvotes: 31

Views: 31086

Answers (3)

Abdul Rehman Khan
Abdul Rehman Khan

Reputation: 172

Simply add comma between different libraries, instead of adding new script.

e.g

<script type="text/javascript"src="http://maps.googleapis.com/maps/api/js?libraries=drawing,places&sensor=false">

you can see the code having comma between 'drawing' and 'places' library.

Upvotes: 1

Ashwani
Ashwani

Reputation: 127

You can use it in this way

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&libraries=places"></script>

Upvotes: -2

Dr.Molle
Dr.Molle

Reputation: 117334

The first script doesn't point to a javascript, this will try to load the maps-homepage as a script(of course this will fail).

There is no need to include multiple scripts, simply use:

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

This will load the maps-API(V3) and includes the places+geometry-libraries

https://developers.google.com/maps/documentation/javascript/libraries?hl=en

However, as Colin said, this looks like V2-code.

Upvotes: 70

Related Questions