Rahul Chidgopkar
Posts: 0
Joined: Tue May 14, 2013 7:11 am

How to read latitude and longitude from Parse Geopoint?

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How to read latitude and longitude from Parse Geopoint?

Where are you running this code..?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How to read latitude and longitude from Parse Geopoint?

Hi Rahul,

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

Rahul Chidgopkar
Posts: 0
Joined: Tue May 14, 2013 7:11 am

How to read latitude and longitude from Parse Geopoint?

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How to read latitude and longitude from Parse Geopoint?

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

Rahul Chidgopkar
Posts: 0
Joined: Tue May 14, 2013 7:11 am

How to read latitude and longitude from Parse Geopoint?

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How to read latitude and longitude from Parse Geopoint?

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

Rahul Chidgopkar
Posts: 0
Joined: Tue May 14, 2013 7:11 am

How to read latitude and longitude from Parse Geopoint?

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.

Rahul Chidgopkar
Posts: 0
Joined: Tue May 14, 2013 7:11 am

How to read latitude and longitude from Parse Geopoint?

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);
}
});

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

How to read latitude and longitude from Parse Geopoint?

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

Return to “Issues”