0

我试图使用 http 适配器检索经纬度。当我尝试调用该过程时,我将能够检索结果。但我只想检索 lat 和 long 而不是其他附加信息。我附上了我的代码。

function getGmapLatLng(pAddress) {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'maps/api/geocode/json',
parameters : {
'address' : pAddress,
'sensor' : 'false' // hard-coded
}
}; 
return WL.Server.invokeHttp(input);
var type = typeof input; 
if ("object" == type) {
if (true == response) {

// Drill down into the response object.
var results = response;
var result = results[0];
var geometry = result;
var location = geometry;
} 
else {

return null;
}
} 
else {
return null;
}

}

谁能纠正我做错的地方

4

1 回答 1

1

这应该是您的适配器:googleMap.xml:

<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="googleMap"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:wl="http://www.worklight.com/integration"
    xmlns:http="http://www.worklight.com/integration/http">
    <displayName>googleMap</displayName>
    <description>googleMap</description>
    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
            <domain>maps.googleapis.com</domain>
            <port>80</port>
        </connectionPolicy>
        <loadConstraints maxConcurrentConnectionsPerNode="2" />
    </connectivity>
    <procedure name="getLangLat"/>
</wl:adapter>

googleMap-impl.js(为简单起见,我对地址进行了硬编码):

function getLangLat() {
    var input = {
        method : 'get',
        returnedContentType : 'json',
        path : 'maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false'
    };
    return WL.Server.invokeHttp(input);
}

您的应用程序 JavaScript:

// Worklight comes with the jQuery framework bundled inside. If you do not want to use it, please comment out the line below.
window.$ = WLJQ;

function wlCommonInit(){
    // Common initialization code goes here
    getLangLat();
}

function getLangLat() {
// Invocation data details
    var invocationData = {
        // Adapter to invoke
        adapter: 'googleMap',
        // Procedure to invoke
        procedure: 'getLangLat',
        parameters: []
    };

    // Invoke procedure
    WL.Client.invokeProcedure(invocationData, {
        // On success callback
        onSuccess : onSuccess,
        // On failure callback
        onFailure : onFail,
        // timeout
        timeout : 30000
    });

}

function onSuccess (results) {
    alert('Latitude: ' + results.invocationResult.results[0].geometry.location.lat);
    alert('Longitude: ' + results.invocationResult.results[0].geometry.location.lng);
}

function onFail (error) {
    WL.Logger.debug(error);
}
于 2012-07-31T16:22:00.380 回答