I want to save address ( a relational object ) with geopoints, so as to later retrieve all Events which have address near to provided location, it will be all based on coordinates. Using following piece of code -
$address = new ParseObject("Address");
$point = new ParseGeoPoint(23.80, -120.90);
$address->set("location", $point);
$address->save();
Type of location in my db is geopoint, but it gives me continuous error-
Internal Server Error . Error code :exception 'Exception' with message 'Can't serialize an unsaved Parse.Object'
Post this I tried following code -
$address = new ParseObject("Address");
$address->save();
$point = new ParseGeoPoint(23.80, -120.90);
$address->set("location", $point);
$address->save();
I tried this, so as to remove above error of unsaved Parse.Object, but it ended up saving only my address object and never saving location in it. How can I achieve this?
Full code view -
function saveEvent() {
$title = $this->input->post('title');
$eventCode = $this->input->post('eventCode');
$event = new ParseObject("Event");
$event->set("title", $title);
$event->set("eventCode", $eventCode);
$address = $this->saveAddressObject($event, $url);
$event_address_Relation = $event->getRelation("address");
if (!empty($address)) {
$event_address_Relation->add($address);
}
$event->save();
}
function saveAddressObject($event, $url) {
$fullAddress = $this->input->post('fullAddress');
$address1 = $this->input->post('address1');
$address2 = $this->input->post('address2');
$city = $this->input->post('city');
$state = $this->input->post('state');
$zipCode = (int) $this->input->post('zipCode');
$country = $this->input->post('country');
$latitude = $this->input->post('latitude');
$longitude = $this->input->post('longitude');
try {
$address = new ParseObject("Address");
$address->set("fullAddress", $fullAddress);
$address->set("address1", $address1);
$address->set("address2", $address2);
$address->set("city", $city);
$address->set("state", $state);
$address->set("zipCode", $zipCode);
$address->set("country", $country);
$address->set("latitude", $latitude);
$address->set("longitude", $longitude);
$point = new ParseGeoPoint($latitude, $longitude);
$address->set("location", $point);
$address->save();
return $address;
} catch (ParseException $error) {
print_r($error);
} catch (Exception $ex1) {
print_r($ex1);
}
}