OpIvy
OpIvy

Reputation: 37

Google Is Not Defined

I'm trying to create a simple app that looks up a Place, but I'm getting a ReferenceError when I try to run it. My current code is taken straight from a Google tutorial, so I'm not sure what I'm missing.

function myFunction()
{
  var map;
  var service;
  var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);

  map = new google.maps.Map(document.getElementById('map'), {
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: pyrmont,
      zoom: 15
      });

  var request = {
    location: pyrmont,
    radius: '500',
    types: ['store']
    };

  service = new google.maps.places.PlacesService(map);
  service.search(request, callback);
}

The error I get is "ReferenceError: "google" is not defined." on this line

var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);

I assume its something simple like some sort of include, but I'm at a loss.

Upvotes: 0

Views: 2606

Answers (2)

Serge insas
Serge insas

Reputation: 46802

Taken from the documentation :

The Places service is a self-contained library, separate from the main Maps API JavaScript code. To use the functionality contained within this library, you must first load it using the libraries parameter in the Maps API bootstrap URL:

See the Libraries Overview for more information.

+1 to Srik Answer : this is indeed not about Google Apps Script

Upvotes: 0

Srik
Srik

Reputation: 7957

Google Apps Script is not the same as Javascript. The code you are writing here is for the JavaScript API of Google Maps. To use Maps in Apps Script, use the classes defined in the Apps Script documentation - https://developers.google.com/apps-script/service_maps

Upvotes: 2

Related Questions