English 中文(简体)
Geocoder未定义的恢复功能
原标题:Function returning undefined in Geocoder

我正在使用谷歌地图对3个地理坐标表,然后通过一个地址,将“j Query”文档中的2个协调点通过到“PHP”文档中getJSON

<>可见> 然而,我注意到,地编码功能的功能保持了一种不确定的价值。 因此,PHP文档可得到一个未界定的变量。 我在哪里错了?

http://www.ohchr.org。

var search_latlng = geocodeAddress(search_location);
console.log(search_latlng);

$.getJSON( /main/get_places , {search_location: search_latlng}, function(json){
        $("#result_listing").html(  );
 .
 .
 .

http://www.ohchr.org。

function geocodeAddress(address) {

    var latlng = new Array(2);

    geocoder.geocode( {  address : address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            latlng[0] = results[0].geometry.location.lat();
            latlng[1] = results[0].geometry.location.lng();
            return latlng;
        } else {
            console.log("Geocode was not successful for the following reason: " + status);
        }
    });
}
最佳回答

你们可以通过向谷歌代法发出呼吁,从这一功能中收回价值。 这毫无意义;“地球编码”功能是asynchronous。 外部职能将在你回击时恢复。

这样做的适当途径是将谷歌普本身 mi为 mi:使你的工作达到退约参数,并从那里开展你“后”工作:

function geocodeAddress(address, callback) {

    var latlng = new Array(2);

    geocoder.geocode( {  address : address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            latlng[0] = results[0].geometry.location.lat();
            latlng[1] = results[0].geometry.location.lng();
            callback(latlng); // call the callback function here
        } else {
            console.log("Geocode was not successful for the following reason: " + status);
        }
    });
}

edit — as an example of how you d use this:

geocodeAddress(search_location, function(search_latlng) {
  console.log(search_latlng);
  $.getJSON( /main/get_places , {search_location: search_latlng}, function(json){
    $("#result_listing").html(  );
    // ...
  });
});

它像你原来的法典一样,但不是把地理编码结果retured<>em>转至你的代码,而是作为你提供的备用功能的参数。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.