[英]how to solve this error in google API?
When I run this code I get the following error 当我运行此代码时,出现以下错误
error: invalid label "html_attributions" : [ --------json?l...4845749 (line 2)
and nothing gets displayed.What changes I have to make in order to get this right and where am I going wrong? 却什么也没显示。为了正确,我必须进行哪些更改?我在哪里出错?
<script src="http://www.mattcashatt.com/Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<input id="Company" type="text" /><input id="goButton" type="button" value="Go" /><div id="Placeholder"></div>
this is my java script: 这是我的Java脚本:
<script type="text/javascript">$('#goButton').click(function(){$.getJSON("https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types="+$('#Company').val()+"&name=harbour&sensor=false&key=AIzaSyC1BIAzM34uk6SLY40s-nmXMivPJDfWgTc&callback=?",function (data){$('#Placeholder').html("");$('#Placeholder').append(<h1>Company name:</h1>" + data.name + "<br/><br/>");$('#Placeholder').append("<h1> page:</h1>" + data.types + "<br/><br/>");$('#Placeholder').append("<h1>Likes:</h1>" + data.vicinity + "<br/><br/>"); });});
Maps v3 does not support callback/JSONP from a jQuery get/getJSON at this time Maps v3目前不支持来自jQuery get / getJSON的回调/ JSONP
http://www.quora.com/Why-doesnt-the-Google-Maps-API-support-JSONP http://www.quora.com/Why-doesnt-the-Google-Maps-API-support-JSONP
That said - if you have the patience try looking at 就是说-如果您有耐心,请尝试看看
http://code.google.com/intl/no-NO/apis/maps/documentation/javascript/services.html#Geocoding http://code.google.com/intl/no-NO/apis/maps/documentation/javascript/services.html#Geocoding
To load async, you need to do something like this: 要加载异步,您需要执行以下操作:
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
document.body.appendChild(script);
}
http://code.google.com/apis/maps/documentation/javascript/basics.html#Async http://code.google.com/apis/maps/documentation/javascript/basics.html#Async
Also PLEASE use a current jQuery - for example like this 还请使用当前的jQuery-例如这样
<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// your code here
});
</script>
you can try this and see what is getting logged in console. 您可以尝试此操作,并查看正在控制台中登录的内容。
<script type="text/javascript">
$('#goButton').click(function(){
$.getJSON("https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types="+$('#Company').val()+"&name=harbour&sensor=false&key=AIzaSjC1BIA2M34uk6SLY401-nmXMivPJDfWgTc&callback=?", function (data){
console.log(data);
$('#Placeholder').html("");
$('#Placeholder').append(<h1>Company name:</h1>" + data.name + "<br/><br/>");
$('#Placeholder').append("<h1> page:</h1>" + data.types + "<br/><br/>");
$('#Placeholder').append("<h1>Likes:</h1>" + data.vicinity + "<br/><br/>");
});
});
</script>
I get something like this: 我得到这样的东西:
{
"html_attributions" : [],
"results" : [],
"status" : "REQUEST_DENIED"
}
so you need use "data" variable accordingly. 因此您需要相应地使用“数据”变量。 Something like data.results etc.
诸如data.results之类的东西
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.