Created
July 26, 2016 12:24
-
-
Save swapnilshrikhande/21adf08730b8a3158e471d62d0cb81e8 to your computer and use it in GitHub Desktop.
Search Nearby Places Google
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style type="text/css"> | |
#map-canvas { | |
height : 500px; | |
} | |
</style> | |
<title></title> | |
<!-- <script> | |
window.initMap = function(){ | |
}; | |
</script> --> | |
<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 type="text/javascript"> | |
var map; | |
<!-- can be removed later--> | |
var service; | |
function handleSearchResults(results,status){ | |
console.log(results); | |
} | |
function performSearch(){ | |
var request = { | |
bounds: map.getBounds(), | |
name : "McDonald's" | |
} | |
service.nearbySearch(request, handleSearchResults); | |
} | |
<!-- above--> | |
function initialise(location){ | |
console.log(location); | |
var currentLocation = new google.maps.LatLng(location.coords.latitude,location.coords.longitude); | |
var mapOptions = { | |
center: currentLocation, | |
zoom: 12, | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}; | |
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); | |
var marker = new google.maps.Marker({ | |
position: currentLocation, | |
map : map | |
}); | |
<!-- can be removed later--> | |
service = new google.maps.places.PlacesService(map); | |
google.maps.event.addListenerOnce(map,'bounds_changed',performSearch) | |
//performSearch(); | |
} | |
$(document).ready(function(){ | |
navigator.geolocation.getCurrentPosition(initialise); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="map-canvas"></div> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment