0

我正在为此工作 2 天,但我不知道发生了什么。

我在谷歌地图上的地址附近寻找 Phamacy 地点:R. Manoel Bandeira, 324-490, Embu - São Paulo, 06846-570, Brazil

如您所见,5公里附近有很多药店

当尝试使用 google places api 在我的网站上执行此操作时。结果是 = 没有。遵循代码有什么想法吗?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false&language=se"></script>
<script>

function init() {

const location=new google.maps.LatLng(-23.6334282, -46.8739405);
const radius = 5000;

// Make map
var mapOptions = {
center: location,
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), mapOptions);

// Make a circle
var circOptions={
center: location,
radius: radius,
map: map
};
circle = new google.maps.Circle(circOptions);  

// Get shops in radius
service = new google.maps.places.PlacesService(map);
var request={                                               //my request
location: location,
radius: radius,
types: ["pharmacy"]
};

service.search(request, function (results, status){
if (status == google.maps.places.PlacesServiceStatus.OK){
for (var i= 0, result; result=results[i]; i++) {     //add markers
distance=google.maps.geometry.spherical.computeDistanceBetween(location, result.geometry.location);
if (distance>radius)
continue;

var marker = new google.maps.Marker({
map: map,
position: result.geometry.location,
reference: result.reference
});
}
}
});

}
google.maps.event.addDomListener(window, 'load', init);

</script>

<style>#map {height: 500px;width: 500px;}</style>
</head>
<body><div id="map"></div></body>
</html>
4

0 回答 0