これはアダプタである必要があります: 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);
}