Created
November 16, 2018 14:40
-
-
Save ivan-kalachikov/fa57fcea06b9a36c0473a7c28c598e86 to your computer and use it in GitHub Desktop.
Google map with info window from place id information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global.initMap = () => { | |
jQuery('.map-canvas').each((index, element) => { | |
let map = jQuery(element); | |
const position = new google.maps.LatLng(map.data('latitude'), map.data('longitude')); | |
const markerIcon = map.data('icon'); | |
const mapZoom = map.data('zoom'); | |
const dataPlaceId = map.data('place-id') || 'null'; | |
let infowindow = new google.maps.InfoWindow(); | |
map = new google.maps.Map(element, { | |
zoom: mapZoom || 17, | |
center: position, | |
disableDefaultUI: true | |
}); | |
var service = new google.maps.places.PlacesService(map); | |
service.getDetails({ | |
placeId: dataPlaceId | |
}, function(place, status) { | |
if (status === google.maps.places.PlacesServiceStatus.OK) { | |
var marker = new google.maps.Marker({ | |
map: map, | |
position: place.geometry.location | |
}); | |
map.setCenter(place.geometry.location); | |
infowindow.setContent('<div><strong>' + | |
place.formatted_address + '</div>'); | |
infowindow.open(map, marker); | |
} else { | |
new google.maps.Marker({ | |
position: position, | |
map: map, | |
icon: markerIcon || '', | |
}); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment