Thursday, May 17, 2012

Display Near by places with Google Places API

[sourcecode language="javascript"]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Google Maps JavaScript API v3 Example: Place Search</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true&libraries=places"></script>

<style type="text/css">
#map {
height: 400px;
width: 600px;
border: 1px solid #333;
margin-top: 0.6em;
}
</style>

<script type="text/javascript">
var map;
var infowindow;

function initialize() {
var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);

map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 15
});

var request = {
location: pyrmont,
radius: 500,
types: ['store']
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.search(request, callback);
}

function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}

function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});

google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map"></div>
<div id="text">
<pre>
var request = {
location: new google.maps.LatLng(-33.8665433, 151.1956316),
radius: 500,
types: ['store']
};
</pre>
</body>
</html>


[/sourcecode]

 

2 comments:

  1. [...] you copy the source code at http://codezone4.wordpress.com/2012/05/17/display-near-by-places-with-google-places-api/ into an HTML file and then view that HTML file as a web page, you get a Google Map showing the [...]

    ReplyDelete
  2. […] you copy the source code at http://codezone4.wordpress.com/2012/05/17/display-near-by-places-with-google-places-api/ into an HTML file and then view that HTML file as a web page, you get a Google Map showing the […]

    ReplyDelete

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...