我想實現一個Maps API V3和本地搜索,但我似乎有問題。不知何故,OnLocalSearch()函數中的結果爲空。Google Maps API V3和本地搜索問題 - 空白結果?
這裏是我的完整代碼:
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
// do stuff when DOM is ready
var geocoder = new google.maps.Geocoder();
var address = '{{string_location}}';
var map;
// Our global state for LocalSearch
var gInfoWindow;
var gSelectedResults = [];
var gCurrentResults = [];
var gLocalSearch = new GlocalSearch();
if (geocoder) {
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//alert(results[0].geometry.location.lat())
//alert(results[0].geometry.location.lng())
//Create the Map and center to geocode results latlong
var latlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
var myOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
gLocalSearch.setSearchCompleteCallback(this, OnLocalSearch);
gLocalSearch.execute("{{business_item.name}}");
}
else {
alert('No results found. Check console.log()');
console.log("Geocoding address: " + address);
console.log("Geocoding failed: " + status);
}
});
}
/*
Other functions
*/
function OnLocalSearch() {
if (gLocalSearch.results[0]) { //This is empty. Why?
var resultLat = gLocalSearch.results[0].lat;
var resultLng = gLocalSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
callbackFunction(point);
}else{
alert("not found!");
}
}
});
//]]>
</script>
僅供參考,我用這作爲一個例子,我被困了幾個小時,現在這個問題:http://gmaps-samples-v3.googlecode.com/svn-history/r136/trunk/localsearch/places.html
任何答覆將不勝感激。
問候, Wenbert
UPDATE 我犯了一個錯誤這裏的某個地方:
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0" type="text/javascript"><;/script>
<script src="http://maps.google.com/maps/api/js?v=3.1&sensor=false®ion=PH"></script>
此外,請務必仔細檢查你的地理編碼地址。我來自菲律賓,Google似乎只對主要道路進行地理編碼。見http://gmaps-samples.googlecode.com/svn/trunk/mapcoverage_filtered.html
感謝來自irc.geekshed.net jgeerdes #googleapis
我們如何通過字符串獲得原始(確切)名稱..? – 2014-04-29 12:11:25