gokhan04186
gokhan04186

Reputation: 11

Google Map Place api

ı am using google place api. this is my code and it is working well but when ı refresh the page after sometime past firebug has been giving me this error google.maps.event is undefined.

ı look firebug's net tab ı saw GET js?sensor=false&libraries=places Aborted maps.googleapis.com

how can ı fix this problem?

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

  var map;
  var infowindow;

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

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


    var request = {
      location: pyrmont,
      radius: 500,
      types: ['school']
    };
    infowindow = new google.maps.InfoWindow();
    var service = new google.maps.places.PlacesService(map);
    service.search(request, callback);
  }

  function callback(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
      for (var i = 0; i < results.length; i++) {
        createMarker(results[i]);
      }
    }
  }

  function createMarker(place) {
    var placeLoc = place.geometry.location;
    var marker = new google.maps.Marker({
      map: map,
      position: place.geometry.location
    });

    google.maps.event.addListener(marker, 'click', function() {
      infowindow.setContent(place.name);
      infowindow.open(map, this);
    });
  }

  google.maps.event.addDomListener(window, 'load', initialize);

Upvotes: 1

Views: 1531

Answers (1)

Govindarajan
Govindarajan

Reputation: 33

Google recommends that you always use the Google API Key in the URL mentioned in the src attribute of the script tag.

js?sensor=false&libraries=places&key=xxxxxxxxxxxxxxxx

Pls try that and let me know.

Regards

Govindarajan

Upvotes: 1

Related Questions