m_highlanderish m_highlanderish - 1 month ago 7
Javascript Question

google maps api cannot read placesservice

I am having a problem with Google's Maps API and its PlacesService. Even though I have the places library properly loaded it keeps saying "Cannot read property 'PlacesService' of undefined". The map itself works and loads. Any ideas? Here's the code:

<div id="map-canvas"></div>

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&libraries=placeā€Œs"></script>
<script type="text/javascript">
var myLatlng;
var map;
var marker;

function initialize() {
myLatlng = new google.maps.LatLng(fooLat, fooLng);

var mapOptions = {
zoom: 17,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: false,
draggable: true
};

map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

var service = new google.maps.places.PlacesService(map);

var request = { placeId: 'fooPlaceId'};
service.getDetails(request, callback);

function callback (place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
marker = new google.maps.Marker({
position: place.position,
map: map,
title: place.name
});
}
};
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>


Update:
I literally just tried a piece of code from Google itself and it gave me the same error.

Answer

Here's the answer: I copied the include line directly from some page (either here, stackoverflow, or one of Googles APIs example pages. What seems to be the problem is that it, for whatever reason, had an invisible character in the name of the library which mine CMS editor didn't pick up on. So beware when copying!