Javascript 在worklight的Http适配器中检索Lat和Long
我正在尝试使用http适配器检索lat和long。当我尝试调用该过程时,我将能够检索结果。但我只想检索lat和long,不想检索其他附加信息。我已附上我的代码Javascript 在worklight的Http适配器中检索Lat和Long,javascript,jquery,ibm-mobilefirst,Javascript,Jquery,Ibm Mobilefirst,我正在尝试使用http适配器检索lat和long。当我尝试调用该过程时,我将能够检索结果。但我只想检索lat和long,不想检索其他附加信息。我已附上我的代码 function getGmapLatLng(pAddress) { var input = { method : 'get', returnedContentType : 'json', path : 'maps/api/geocode/json', parameters : { 'address' : pAddress, 'senso
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;
}
}
谁能纠正我哪里做错了这应该是你的适配器: 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>
您的应用程序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);
}
// 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);
}