2

I'm trying to get lat long coordinates from an address using the Google maps api v3 in Wakanda Studio. I have submitted to the Wakanda forum as well. I searched the v3 documentation as well, which basically advises to pass a JSON object and a call back function to geocode, which is displayed in the code below.

The geocode call is also encapsulated in the codeAddress function. When I run the code, I can see the Geocoder JSON object results that include the lat long coordinates. However, I am getting a strange error message:

Uncaught Error Type: Object #<Object> has no method 'apply'

Any pointers would be appreciated, and let me know if you need to see screenshots/details of anything else emailed, since I cannot post screenshots on stack overflow yet.

button1.click = function button1_click (event)
{
    $$('map').setCenter("London, England");     
    var address1 = "911 South Park Street, Kalamazoo, MI, 49001";

    geocoder = new google.maps.Geocoder();

    if(!geocoder) {
        alert("no geocoder available");
    } else {
        alert("geocoder available");
    }

    codeAddress(address1);
};

function codeAddress(address) {

    var address1 = address;
    geocoder.geocode(
        {'address': address1},
        {onSuccess: function(results, status) {

            if (status == google.maps.GeocoderStatus.OK) {
                //setCenter to mid
                //addMarker
                var lat = results[0].geometry.location.lat;
                var lon  = results[0].geometry.location.lon;
                alert(lat);
            } else {
                alert("geocoder issue " + status);
            }
        }
    });

}

Whoosh ValueError: Keys must increase

I'm getting the error

ValueError: Keys must increase: '\x00\x00\x0b\xc4\x00\x01' .. '\x00\x00\x0b\xc4\x00\x01'

at the line

writer.commit() 

Where writer is an index.writer. I am adding 10K files to the index, and for performance, I commit every 100 files. This error only occurs at the 21st commit (20999 files).

The stack ends at add_all in whoosh...\filetables.py

4

1 回答 1

2

我也在 Wakanda 中尝试过类似的方法,但由于 CORS(域的交叉引用),浏览器似乎阻止了调用,所以我使用了以下方法。

Wakanda 客户端 --> Wakanda 服务器 --> Google Maps API --> 返回 Wakanda 服务器 --> 返回 Wakanda 客户端

客户端代码:

button1.click = function button1_click (event) {
    var address = $$("addressField").getValue();
    address = encodeURI(address);
    // Make call to server
    response = $sources.businesses.getGeoCoordinates(address);
    address_info = JSON.parse(response);

    if (address_info && address_info.status === "OK") {
        $$("business_latitude_field").setValue(
            address_info.results[0].geometry.location.lat
        );
        $$("business_longitude_field").setValue(
            address_info.results[0].geometry.location.lng
        );
        alert('We got latitude & longitude of your address.');
    } else {
        alert("Could not find latitude and longitude of your given address.");
    }
}

服务端代码——业务数据类中getGeoCoordinates公共方法的代码

function (address) {
    // Call google geocode service to convert given address into lat / long
    if (address) {
        var api_url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=" + address;
        xhr = new XMLHttpRequest();
        xhr.open("GET", api_url);
        xhr.send();
        var response = xhr.responseText;
        return response;
    }
}

希望能帮助到你。

于 2013-10-29T07:54:41.473 回答