0

I have succesfuly stored some geopoints in Parse.com and now in another page i want to console log them all so i can place them into some variables and then put one marker in google map. So i'm trying with this code to get them but for sure i miss some thing and i need your advice.

    Parse.initialize("APPID", "JSKEY");
    var PhotoObject = Parse.Object.extend('magazia');
    var photoObject = new PhotoObject();
    var query = new Parse.Query(PhotoObject);
    query.select('latlon');
    query.find({
        success: function(locationList) {
            alert("Successfully retrieved " + locationList.length + " locations.");
            for (var i = 0; i < locationList.length; i++) {
                var locationsBlock = {};
                locationsBlock = JSON.parse(JSON.stringify(locationList[i]));
                var location = {};
                location = JSON.parse(JSON.stringify(locationsBlock.geolocation));
                alert(location.latitude);
            };
        },
        error: function(error) {
            alert("Error: " + error.code + " " + error.message);
        }
    });

So i have a class called "magazia" and inside that class there is a column which is called "latlon" and its a Geopoint. The content of this column is for example 48.29124, 28.52015 float number. The alert shows me the correct number of rows that there are in the "magazia" class.

Does anyone knows why i dont get the results from my code above? thanks in advance.

Konstantinos Natsios
  • 2,874
  • 9
  • 39
  • 74
  • why are you moving from the parse object into JSON text and then into a plain JS object? And then from that plain JS to JSON text and back to a plain JS object? – Wain Jan 21 '16 at 09:29
  • @Wain i wanted to post only the latitude for example and i was just trying some stuff... Not sure how to do it and parse.com documentation is not very helpfull about geopoints, you have any idea? – Konstantinos Natsios Jan 21 '16 at 09:35
  • you just `get` the geopoint from the object and ask for the `laltitude` and `longitude`. are you saying the alert doesn't show the latitude? – Wain Jan 21 '16 at 09:38
  • @Wain nope, i only get the first alert, after it nothing happens. – Konstantinos Natsios Jan 21 '16 at 10:01

1 Answers1

0

Ok that was a stupid mistake

 var PhotoObject = Parse.Object.extend('magazia');
    var photoObject = new PhotoObject();
    var query = new Parse.Query(PhotoObject);
    query.select('latlon');
    query.find({
        success: function(locationList) {
            console.log("Successfully retrieved " + locationList.length + " locations.");
            for (var i = 0; i < locationList.length; i++) {
                var locationsBlock = {};
                locationsBlock = JSON.parse(JSON.stringify(locationList[1]));
                var location = {};
                location = JSON.parse(JSON.stringify(locationsBlock.latlon));

                var lat = location.latitude;
                var lon = location.longitude;
                console.log(lat, lon);
            };
        },
        error: function(error) {
            alert("Error: " + error.code + " " + error.message);
        }
    });

instead of locationsBlock.geolocation there should be locationsBlock.latlon

Konstantinos Natsios
  • 2,874
  • 9
  • 39
  • 74