I'm facing a problem that (in my case) not all bakeries are shown in the example code though Google definitely knows about them since I find them in other searches.
For example, the two bakeries at 52.543770, 13.441250 are not shown though they're within the specified radius. Why is this and how to fix it? I want to find all bakeries that Google knows of and not just a part of it.
<!DOCTYPE html>
<html>
<head>
<title>Place searches</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
<script>
var map;
var infowindow;
function initMap() {
var berlin = {lat: 52.540, lng: 13.430};
map = new google.maps.Map(document.getElementById('map'), {
center: berlin,
zoom: 15
});
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: berlin,
radius: 2000,
types: ['bakery']
}, 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);
});
}
</script>
</head>
<body>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&signed_in=true&libraries=places&callback=initMap" async defer></script>
</body>
</html>