Score:0

Programmatically set latitude and longitude exposed input

in flag

I've been using geolocation 8.x-1.12 for a while now. I have a REST route that gets a view with my exposed form and returns the results.

Previously I did:

$plugin = \Drupal::service('plugin.manager.geolocation.geocoder');
$geocoder = $plugin->getGeocoder('google_geocoding_api');
$geocode = $geocoder->geocode($zip_code);

$view = Views::getView('local_pharmacies');
$view->setDisplay('block_1');
$exposed = [
  'field_geolocation_proximity-lat' => $geocode['location']['lat'], // No longer exists in 3.x
  'field_geolocation_proximity-lng' => $geocode['location']['lng'], // No longer exists in 3.x
  'field_geolocation_proximity' => "50",
];
$view->setExposedInput($exposed);
$view->preExecute();
$view->execute();

I updated to 8.x-3.7 because I plan to upgrade to D9 soon. The above is no longer working. I think because field_geolocation_proximity-lat and field_geolocation_proximity-lng no longer exist. I tried diving into the source as well as kinting form alters to figure out how to properly set the coordinates but I cannot figure it out. Any ideas?

Score:2
in flag

I finally figured out how its supposed to be formatted. Kinting after the view execute rather than before exposed the field names.

$exposed = [
  'center' => [
    'coordinates' => [
      'lat' => $geocode['location']['lat'],
      'lng' => $geocode['location']['lng'],
    ],
  ],
  'field_geolocation_proximity' => "50",
];
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.