Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Last active August 2, 2016 13:42
Show Gist options
  • Save swapnilshrikhande/b40842d762a1206cb3f20a8b5d27c07c to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/b40842d762a1206cb3f20a8b5d27c07c to your computer and use it in GitHub Desktop.
Find nearby places
<apex:page id="pageId" controller="AccountGeoLocationDemo">
<head>
<style type="text/css">
#map-canvas {
height : 512px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyBMFdqVZd9idw-0pYEsWQ9xxM9mNz7f9E4">
</script>
<script>
var map;
var classInstances;
function initialise(location){
var currentLocation = new google.maps.LatLng(location.coords.latitude,location.coords.longitude);
var mapOptions = {
center: currentLocation,
zoom: 1,
minZoom : 1,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.AccountGeoLocationDemo.AccountGeoLocationDemo}',
function(result, event) {
classInstances = result;
console.log(classInstances);
for(i= 0;i<classInstances.length;i++){
var latlng = new google.maps.LatLng(classInstances[i].BillingLatitude,classInstances[i].BillingLongitude);
console.log(latlng);
var marker = new google.maps.Marker({
position:latlng,
map : map
});
infoWindow(marker, map ,classInstances[i].Name,classInstances[i].Id);
}
});
}
function infoWindow(marker, map, name,Id) {
google.maps.event.addListener(marker, 'mouseover', function() {
console.log('Yooo');
var html = "<div><h3>" + name + "</h3></div>";
iw = new google.maps.InfoWindow({
content: html,
maxWidth: 350
});
iw.open(map, marker);
});
google.maps.event.addListener(marker, 'click', function() {
console.log('Hello');
window.location = '/' + Id;
});
}
$(document).ready(function(){
navigator.geolocation.getCurrentPosition(initialise);
});
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment