Comentarios (8)

1 KinGPinG ha hecho un comentario el Enlace permanente

This is a great tutorial. I'm starting to develop mobile apps with IBM Worklight and it looks very good so far. Regarding this example, when you said:

 
////--------------------------------------------------------------------------------------------------------------------------------------------------------
I added some additional javascript in myRESTAdapter-impl.js to drill down into the response JSON and extract the latitude and longitude values:
 
 
// Extract latitude and longitude from the response.
var type = typeof response
if ("object" == type) {
if (true == response["isSuccessful"]) {
 
// Drill down into the response object.
var results = response["results"];
var result = results[0];
var geometry = result["geometry"];
var location = geometry["location"];
 
// Return JSON object with lat and lng.
return location;
}
else {
// Returning null. Web request was not successful.
return null;
}
}
else {
// Returning null. Response is not an object.
return null;
}
 
//////////////-------------------------------------------------------------------------------------------------------------------------------------------------
 
 
Where does this code go? in a new javascript? Does it go in the function getGmapLatLng(pAddress) ? I got lost at this point. In advance, Thanks for your time.
 

2 noteG ha hecho un comentario el Enlace permanente

Nice Article. I could run the code with necessary changes.
For step 3. following changes worked.

 
return myNewMethod(WL.Server.invokeHttp(input));
 
----****-----
 
function myNewMethod(response){
var type = typeof response;
if ("object" == type) {
if (true == response["isSuccessful"]) {
.....
....
}
 
thanks...

3 RafiqAli195 ha hecho un comentario el Enlace permanente

i'm getting the following exception when i tried creating this example.

 
{
"errors": [
"Runtime: Http request failed: java.net.UnknownHostException: maps.googleapis.com"
],
"info": [
],
"isSuccessful": false,
"warnings": [
]
}

4 SarathSaleem ha hecho un comentario el Enlace permanente

Good..

 
I tried something similar.. But im getting an JSON parse error in invoking the adapter, My parameters are also similar.. In error console. It will show like arr ={[ method : 'get',
returnedContentType : 'json',
path : 'path\/path\/path\/path',
parameters : {
'param1' : param1,
'param1' : 'param1'
}
};
]} parse error.
 
So im not understanding the parse error is coming from while invoking or the server to which im sending the JSON is not able to parse the request.
 
The parameters the i need to send is just in 'parameters ' only ..? Is worklight is sending the whole thing to the server..?
 
The issue is similar to http://www.ibm.com/developerworks/forums/thread.jspa?threadID=465182

5 Y1F5_poonam_yadav ha hecho un comentario el Enlace permanente

@KinGPinG : Did you solve your problem. I am also stuck at the same point and can not go ahead. Please let me know how did you solve that problem.

 
Thanks in advance.

6 IBMrk ha hecho un comentario el Enlace permanente

Now the access has been denied

 
{
"errors": [
"Runtime: Http request failed: org.apache.http.conn.HttpHostConnectException: Connection to http:\/\/maps.googleapis.com:8080 refused"
],
"info": [
],
"isSuccessful": false,
"warnings": [
]
}

7 levantoan ha hecho un comentario el Enlace permanente

function getGmapLatLng(pAddress) {

 
var input = {
method : 'get',
returnedContentType : 'json',
path : 'maps/api/geocode/json',
parameters : {
'address' : pAddress,
'sensor' : 'false' // hard-coded
}
};
 
return getExtractGmapLaLng(WL.Server.invokeHttp(input));
}
// 4250 South Miami Boulevard, Durham, NC, USA
 
function getExtractGmapLaLng(response){
// Extract latitude and longitude from the response.
var type = typeof response ;
if ("object" == type) {
if (true == response["isSuccessful"]) {
 
// Drill down into the response object.
var results = response["results"];
var result = results[0];
var geometry = result["geometry"];
var location = geometry["location"];
 
// Return JSON object with lat and lng.
return location;
}
else {
// Returning null. Web request was not successful.
return null;
}
}
else {
// Returning null. Response is not an object.
return null;
}
}

8 marco-123 ha hecho un comentario el Enlace permanente

Great tutorial, thank you.
Is it possible to extract some JSON fields (latitude and longitude, as in your example) using a XSL file (as done in some examples in the worklight tutorial) instead of doing the parsing with javascript code?
Thank you again