You are here

function geocoder_field_widget_values_from_geometry in Geocoder 7.2

Geocoder Widget - Field values from geometry

Given a geometry and the field type, return back a values array for that field. The passed back array represents a single delta.

1 call to geocoder_field_widget_values_from_geometry()
geocoder_field_widget_resolve_deltas in modules/geocoder_field/geocoder_field.module
Geocoder Widget - Resolve Deltas

File

modules/geocoder_field/geocoder_field.module, line 478

Code

function geocoder_field_widget_values_from_geometry($geometry, $target_info) {
  if ($target_info['type'] == 'geofield') {
    return geofield_get_values_from_geometry($geometry);
  }
  if ($target_info['type'] == 'geolocation_latlng') {
    $centroid = $geometry
      ->centroid();
    $lat = $centroid
      ->y();
    $lng = $centroid
      ->x();
    return array(
      'lat' => $lat,
      'lng' => $lng,
      'lat_sin' => sin(deg2rad($lat)),
      'lat_cos' => cos(deg2rad($lat)),
      'lng_rad' => deg2rad($lng),
    );
  }
  if ($target_info['type'] == 'location') {
    $centroid = $geometry
      ->centroid();
    return array(
      'latitude' => $centroid
        ->y(),
      'longitude' => $centroid
        ->x(),
      'source' => 2,
    );
  }
  if ($target_info['type'] == 'postgis') {
    $srid = $geometry
      ->getSRID() ? $geometry
      ->getSRID() : '4326';
    $type = $target_info['settings']['type'];
    $postgis_geometry = new PostgisGeometry($type, $srid);
    $postgis_geometry
      ->fromText($geometry
      ->asText());
    $postgis_geometry
      ->transform($target_info['settings']['srid']);
    return array(
      'geometry' => $postgis_geometry
        ->getGeometry(),
    );
  }
  return array();
}