gpt4 book ai didi

javascript - Google 地方信息 API - 详细信息

转载 作者:行者123 更新时间:2023-11-28 04:24:50 24 4
gpt4 key购买 nike

我正在尝试从 google 获取 2 个详细信息。评论和评级。问题是我似乎无法让 HTTP GET 返回任何内容。

这是我的代码:

$.ajax({
url: "https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJz153jtgN1oYRQeG2PvY5sWc&key=MyAPIKey",
type: "GET", /* or type:"GET" or type:"PUT" */
dataType: "jsonp",
data: {
},
success: function (placesRequest) {
console.log(placesRequest);
},
error: function () {
console.log("Your code sucks, fix the HTTP request");
}
});

错误:

未捕获的语法错误:意外的标记:

enter image description here

如果我点击其中的链接,我会看到以下内容:

enter image description here

这是Google Docs Link .

我做了什么:

  1. 设置我的 API key 。
  2. 找到了我的公司地点 ID:ChIJz153jtgN1oYRQeG2PvY5sWc

任何指示或指示将不胜感激。

最佳答案

尝试下面的解决方案 fiddle ,

https://jsfiddle.net/upsidown/yfawx50v/

function initialize() {
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(0, 0),
zoom: 15
});

var service = new google.maps.places.PlacesService(map);

service.getDetails({
placeId: 'ChIJz153jtgN1oYRQeG2PvY5sWc'
}, function (place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {

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

// Center map on place location
map.setCenter(place.geometry.location);

// Get DIV element to display opening hours
var opening_hours_div = document.getElementById("opening-hours");

// Loop through opening hours weekday text
for (var i = 0; i < place.opening_hours.weekday_text.length; i++) {

// Create DIV element and append to opening_hours_div
var content = document.createElement('div');
content.innerHTML = place.opening_hours.weekday_text[i];
opening_hours_div.appendChild(content);
}
}
});
}

initialize();

关于javascript - Google 地方信息 API - 详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45154506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com