Skip to content

Instantly share code, notes, and snippets.

@tadija
Last active December 12, 2015 09:49
Show Gist options
  • Save tadija/4754959 to your computer and use it in GitHub Desktop.
Save tadija/4754959 to your computer and use it in GitHub Desktop.
JS: google map with place data
// set google maps
function initGoogleMaps() {
var loc, map, opt, id, ref;
// whole map
loc = new google.maps.LatLng(44.826535, 20.384703);
opt = {
zoom: 14,
scrollwheel: false,
center: loc,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), opt);
// nklasa google place marker
loc = new google.maps.LatLng(44.816215, 20.372601);
id = 'nklasa';
ref = 'CnRuAAAAmcJNmQ_E3-l-HTEq8CPbj9p-xf2zjAlMUdRzRwLSK97f9w4IQMBX9QVUgPOtqQbj9JA3jGWCAgWKTPFiu8XcHQxyDnJjYwmJZfpIIdSkWPQGVdoKCqwWY5GS1D4NYVCN60WPk1McVt6dxgsMOM2EkhIQTKyrBdR4DeMMgNoAMIyvNhoUIS_cF7H9Ynb_tNNmNnCjG3JAx9M';
pixOff = new google.maps.Size(-229, -149);
placeMarker(map, loc, id, ref, pixOff);
// flojd google place marker
loc = new google.maps.LatLng(44.841143, 20.390561);
id = 'flojd';
pixOff = new google.maps.Size(30, -33);
ref = 'CnRvAAAAt-rWS-3GyF2MgctpD8BEcT190qma3R0hQg_ynrktZu_wyrCG3HXUYkXf21rD_XzxQkyLmZ5FgkYn1D0oED3-Mrz80-G0e5i3oX9KYItvwd6FUOrIbDpH3HUBD2GOOU6I9gUEEXYaQi1cnh9xIBe4GRIQQAMWVO7uTi0-A0e86LQEGhoUcE9YKsZPI9xDSpQOjdxJh58fKWQ';
placeMarker(map, loc, id, ref, pixOff);
}
// set markers
function placeMarker(map, loc, id, ref, pixOff) {
var marker = new google.maps.Marker({
map: map,
position: loc,
icon: 'assets/img/marker.png'
});
var request = {
reference: ref
};
var service = new google.maps.places.PlacesService(map);
service.getDetails(request, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
contentString = '<div id="'+id+'_infobox" class="infobox">'+
'<address>'+
'<h4><a href="'+place.url+'" target="_blank">'+place.name+'</a></h4><br>'+
''+place.vicinity+'<br>'+
''+place.international_phone_number+'<br>'+
'<a href="mailto:'+id+'@regvoz.com">'+id+'@regvoz.com</a>'+
'</address>'+
'</div>';
var infobox = new InfoBox({
content: contentString,
disableAutoPan: false,
maxWidth: 200,
pixelOffset: pixOff,
zIndex: null,
boxStyle: {
opacity: 0.85,
width: "200px"
},
closeBoxMargin: "4px 4px 0px 0px",
closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
infoBoxClearance: new google.maps.Size(1, 1)
});
infobox.open(map, marker);
google.maps.event.addListener(marker, 'click', function() {
infobox.open(map, marker);
map.setZoom(16);
map.panTo(loc);
});
$('#'+id+'_zoom').bind('click', function() {
infobox.open(map, marker);
map.setZoom(16);
map.panTo(loc);
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment