codycustard
codycustard

Reputation: 548

Geopoint defaults to 0,0 when saving in Parse.com (Javascript SDK)

When I attempt to save a GeoPoint along with my 'NewLog' Parse Object, the GeoPoint always defaults to 0,0. Using the below code the locationLat and locationLong contains a valid geolocation which saves as expected into the locationLat/Long fields.

var locationLat = $("#locationLat").val();
var locationLong = $("#locationLong").val();
var NewLog = Parse.Object.extend("NewLog");
var newLog = new NewLog();

var locationString = locationLat + ", " + locationLong;
console.log(locationString);

var location = new Parse.GeoPoint(locationString);

newLog.set("location", location);
newLog.set("locationLat", locationLat);
newLog.set("locationLong", locationLong);

I can use new Parse.GeoPoint(-36.82655429726454, 174.4372643280756); without any problems, and the log for locationString also looks correct. The GeoPoint just doesn't seem to accept a variable with any variation of syntax I've tried.

Upvotes: 2

Views: 997

Answers (1)

Satyajit
Satyajit

Reputation: 3859

Looks like GeoPoint only accepts number & not strings, so you could try this

var location = new Parse.GeoPoint({latitude: parseFloat(locationLat), longitude: parseFloat(locationLong)});

Upvotes: 5

Related Questions