我对以下代码有同样的问题:
function getpgisdata() {
sdata = ads.d;
var send = $.post("csqcity.php", { variable:sdata }, function pgisquery(data) {
alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
send.complete(function(){ alert("second complete");
});
该函数由以下方式调用:
<div class="wrapSearch">
<div>
<input id="searchTextField" type="text" size="50" placeholder="Enter an address...">
<input type="submit" name="search" id="search1" onclick="getpgisdata()">
</div>
<div class="listWrap" id="listWrap1">
<ul class="searchList" id="searchList1">
</ul>
</div>
错误是:使用 Firebug
TypeError: this is undefined
...n!a?l:Sd(this.lat(),a.lat())&&Sd(this.lng(),a.lng())};P[H].equals=P[H].b;P[H].la...
{main,places}.js (line 11)
与谷歌
Uncaught TypeError: Cannot call method 'lat' of undefined
%7Bmain,places%7D.js:11
csqcity.php 包含:
index.html 中引用了以下库:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
<link rel="stylesheet" type="text/css" href="http://dev.openlayers.org/releases/OpenLayers-2.12/theme/default/style.css"/>
<link rel="stylesheet" type="text/css" href="http://dev.openlayers.org/releases/OpenLayers-2.12/examples/style.css"/>
<script type="text/javascript" src="http://dev.openlayers.org/releases/OpenLayers-2.12/OpenLayers.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
我还有另外 2 个功能。一个是 Google Autocompleter,另一个绘制 Openlayers 地图。该错误与谷歌库有关,因此我还附上了自动完成器代码:
function initialize() {
input = document.getElementById('searchTextField');
var options = {
componentRestrictions: {country: 'us'},
//componentrestrictions: {administrative_area2: 'tx'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
//var place = autocomplete.getPlace();
var place = autocomplete.getPlace();
ads.d = place.geometry.location;
});
}
google.maps.event.addDomListener(window, 'load', initialize);
有人有什么想法吗?先感谢您!