Page 1 of 1

How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 10:30 am
by Rahul Chidgopkar

Hi,

I'm retrieving a set of geopoints from Parse backend. I used alert(JSON.stringify(locationList[0])); to check the response and this is what I got
Image

I tried to set the latitude value by using
var lat = locationList[0].geopoint.latitude;
and checked using alert(lat);

But I'm not getting any dialog box. Am I missing something?

Thanks,
Rahul.


How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 11:20 am
by maxkatz

Where are you running this code..?


How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 11:25 am
by Kateryna Grynko

Hi Rahul,

There is a typo:
codevar lat = locationList[0].geolocation.latitude; /code


How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 12:01 pm
by Rahul Chidgopkar

Max, I'm running this code in my main.js file.
Katya, I tried locationList[0].geolocation.latitude too. it's not working.

This is my code:
var PhotoObject = Parse.Object.extend('photo');
var photoObject = new PhotoObject();
var query = new Parse.Query(PhotoObject);
query.select('geolocation');
query.find({
success: function(locationList) {
alert("Successfully retrieved " + locationList.length + " photos.");
alert(locationList[0].geolocation.latitude);
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});

The first alert for locationList.length is giving correct value, but the second alert is causing this error in console:

Image

It is failing at locationList[0].geolocation because that is returning undefined. I don't know how multi level JSON is supposed to be read.

This might be a very silly problem, but I really appreciate your help.

Thanks,
Rahul.


How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 12:44 pm
by Kateryna Grynko

Rahul,

Please check the code, first lines should be the following:
codevar PhotoObject = Parse.Object.extend('photo');
var photoObject = new PhotoObject();
var query = new Parse.Query(photoObject); /code


How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 1:01 pm
by Rahul Chidgopkar

Katya,

I tried your code above. it is giving me this error Image

Even though your code looks perfectly ok, I don't it'll solve the issue. My old code was retrieving all the data correctly. it was simply a matter of reading the JSON. I put the JSON response in my console and used locations[0].geolocation.latitude and it worked perfectly.

Could it be some hosting setting, etc which could be causing this?

Thanks,
Rahul.


How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 1:15 pm
by Kateryna Grynko

Could you please give us a public link to your app?


How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 2:01 pm
by Rahul Chidgopkar

Katya, I have shared the app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a. The app name is Monitorly Web. Will appreciate some quick help. I have to demo this on Friday.

Thanks,
Rahul.


How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 2:27 pm
by Rahul Chidgopkar

I finally got the code to work by trying out some crazy combination. This is what is working now, but I don't think it's the right way to do it. Will appreciate corrections/improvements
var PhotoObject = Parse.Object.extend('photo');
var photoObject = new PhotoObject();
var query = new Parse.Query(PhotoObject);
query.select('geolocation');
query.find({
success: function(locationList) {
alert("Successfully retrieved " + locationList.length + " photos.");
for (var i = 0; i < locationList.length; i++) {
var locationsBlock = {};
locationsBlock = JSON.parse(JSON.stringify(locationList));
var location = {};
location = JSON.parse(JSON.stringify(locationsBlock.geolocation));
alert(location.latitude);
};
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});


How to read latitude and longitude from Parse Geopoint?

Posted: Wed Jun 12, 2013 3:34 pm
by Maryna Brodina

Hello! Sorry, it's outside the scope of our support. If you'll have any problem - let us know.