Пример #1
0
 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());
 }
Пример #2
0
 /**
  * @param mixed $value
  * @param Field $field
  *
  * @return GeoPoint
  */
 public function decodeGeoPoint($value, Field $field)
 {
     return GeoPoint::fromArray($value);
 }
Пример #3
0
 /**
  * @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()]]]]];
 }
Пример #4
0
 /**
  * @param GeoPoint $geoPoint
  * @param Field $field
  *
  * @return mixed
  */
 public function encodeGeoPoint(GeoPoint $geoPoint, Field $field)
 {
     return [$geoPoint->getLongitude(), $geoPoint->getLatitude()];
 }