【发布时间】:2016-04-07 15:19:24
【问题描述】:
我是 javascript 新手,我正在做一个需要谷歌地图的项目。 我需要使用文本搜索功能查找附近的兽医请求邮政编码不起作用,我有几个问题。
我是否需要 API 密钥才能使用服务场所?
我复制了谷歌地图的代码文档,但不了解回调函数,我不知道我做的事情是否有问题。 如果有人知道代码有什么问题,我将非常感谢您的回复。
这是我的代码:
<script src="https://maps.googleapis.com/maps/api/js?callback=ini&sensor=false&libraries=places"></script>
<script type="text/javascript">
var map;
var vet= " veterinarys";
ini();
function ini()
{
var mapOptions =
{
center: new google.maps.LatLng(37.7831, -122.4039 ),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map"), mapOptions);
var request =
{
radius: '500',
query: vet,
type: ['veterinary_care']
};
service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
createMarker(results[i]);
}
}
}
</script>
【问题讨论】:
-
服务返回的状态是什么?如果它不是“OK”,你的代码不会做任何事情让你知道。
-
我不知道,我复制了这个函数,因为在 Google Maps API 文档和其他示例中是相同的。但问题不存在。
标签: google-maps-api-3 google-api