在工作灯中的Http适配器中检索Lat和Long
Retrieving Lat and Long in Http Adapter in worklight
我正在尝试使用http适配器检索lat和long。当我尝试调用过程时,我将能够检索结果。但我只想检索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;
}
}
有人能纠正我哪里做错了吗
这应该是您的适配器: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);
}
相关文章:
- 使用JSP从服务器检索和显示图像
- 通过Magento的网络服务检索运费
- 如何通过php页面将数据库值检索到jquery自动完成框中
- 无法使用javascript检索SPList项
- 可以't使用Angular解析/检索JSON
- GoogleFeed正在检索图像
- 通过ajax将坐标传递到php服务器端,并在处理后检索到javascript
- 使用Scala Play Framework视图中的键检索映射值
- 从数据库中检索字段,而不模拟它们
- 如何在corona sdk中从CK编辑器中检索数据
- 如何使用Javascript客户端对象模型检索Sharepoint 2010列表项权限
- JavaScript函数未返回谷歌地图lat/long的值
- 在Node.js中上传和检索图像
- Possibile使用Manifest v2下的HTML5地理位置API将lat/long转换为国家/地区
- XML2JSON并检索数据
- 如何从php返回的JSON中检索值
- 如何在.js函数中检索来自其他模板的表单的目标值
- 使用ASP.NET将谷歌地图添加到项目中,并从数据库中检索位置
- 使用javascript进行JSON数据检索
- 在工作灯中的Http适配器中检索Lat和Long