我正在使用google map api for web ... 我也直接从jquery到搜索地点调用附近的api搜索, 这是控制台中的错误 这是网络中的响应
我已经添加了在google api控制台中使用所有引荐来源的api。
1505914946.350596 [0 127.0.0.1:39102] "SELECT" "0"
1505914946.351143 [0 127.0.0.1:39102] "SETEX" "laravel:bar" "600000" "s:3:\"baz\";"
答案 0 :(得分:0)
尝试在dataType : 'jsonp'
来电中添加$.ajax
,
$.ajax({
url: "https://maps.googleapis.com/maps/api/place/nearbysearch/json?" + jQuery.param(param),
method: "GET",
dataType : 'jsonp',
async: false,
success: function(resp) {
console.log(resp);
},
error: function(error) {
console.log(error);
}
});
希望这有帮助!
答案 1 :(得分:0)
请勿在客户端使用javascript中的Places API web service,请使用Google Maps Javascript API v3 Places Library。
proof of concept fiddle (using the posted request parameters)
代码段
var map;
var service;
var infowindow;
function initialize() {
var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);
map = new google.maps.Map(document.getElementById('map'), {
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: '3000',
type: ['church']
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(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]);
}
}
}
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);
html,
body,
#map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<div id="map"></div>