How to customise Google Location Suggest Api to get list of nearby places in Javascript
Posted By : Deepak Agrawal | 30-Oct-2014
Google location suggest api suggest nearBy locations names but we do not get access list of these places. Below code helps to get list of such places.
Sometimes we need to get access near by location to show data according to user location. Then this is the best way to get user location details.
Below code find top 5 nearest places to you for the search term 'oodles':
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places&v=3.exp"></script>
<script>
var service = new google.maps.places.AutocompleteService();
var search="Oodles"
service.getPlacePredictions({
input: search,
offset: search.length
}, function listentoresult(list, status) {
if (status != google.maps.places.PlacesServiceStatus.OK || list==null ) {
return;
}
var results = document.getElementById('results');
for (var i = 0, prediction; prediction = list[i]; i++) {
results.innerHTML += '<li>' + prediction.description + '</li>';
}
});
</script>
</head>
<body>
<p>Query suggestions for 'Oodles':</p>
<ul id="results"></ul>
</body>
</html>
Query suggestions for 'Oodles':
Thank you
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Deepak Agrawal
Deepak is an bright developer with experience in Groovy and Grails. He is well versed with AngularJS.