public function testGeoPointType() { $message = NestedMessage::create(); $geoJson = '{"type":"Point","coordinates":[102.0,0.5]}'; $point = GeoPoint::fromArray(json_decode($geoJson, true)); $message->set('location', $point); $this->assertSame($message->get('location')->getLatitude(), 0.5); $this->assertSame($message->get('location')->getLongitude(), 102.0); $this->assertSame($message->toArray()['location'], $point->toArray()); }
/** * @param mixed $value * @param Field $field * * @return GeoPoint */ public function decodeGeoPoint($value, Field $field) { return GeoPoint::fromArray($value); }
/** * @param GeoPoint $geoPoint * @param Field $field * * @return mixed */ public function encodeGeoPoint(GeoPoint $geoPoint, Field $field) { return ['M' => ['type' => [self::TYPE_STRING => 'Point'], 'coordinates' => ['L' => [[self::TYPE_NUMBER => (string) $geoPoint->getLongitude()], [self::TYPE_NUMBER => (string) $geoPoint->getLatitude()]]]]]; }
/** * @param GeoPoint $geoPoint * @param Field $field * * @return mixed */ public function encodeGeoPoint(GeoPoint $geoPoint, Field $field) { return [$geoPoint->getLongitude(), $geoPoint->getLatitude()]; }