Update Latitude Longitude for imported Venues

WordPress Event Management, Calendars & Registration Forums General Question Update Latitude Longitude for imported Venues

This topic contains 2 replies, has 2 voices, and was last updated by  Sadik Bhimani 6 years, 9 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27899

    Hi

    We are importing about 5000+ old events into this addon. There are 3184 Venues! 🙂

    I just imported the venues into the addon using this plugin and wp-cli
    https://gist.github.com/stephenharris/00a6a601b274b38a59cc82c146a95688

    However, unfortunately we do not have the latitude / longitude data in our old system. If I go to edit the imported Venue and manually retype the address, sometimes the map finds the latitude / longitude and I can then update the venue, but sometimes it remains stuck at 0 /0.

    Morever, it’s not possible to manually update 3000+ venues. Is there any way we can mass update the latitude / longitude for the venues? I am fine with php / wp-cli etc if you can suggest any solution.

    Thanks,

    Sadik Bhimani
    #27902

    Hi Sadik,

    The venue admin page uses Google’s JavaScript API to handle the reverse geocoding. You can’t (easily) use this in a PHP script to process pre-existing venues, but there are PHP alternatives: http://geocoder-php.org/Geocoder/

    You could create a WP Cli command which:

    • Uses eo_get_venues() (docs) to retrieve all the venues
    • Loop through them and use eo_get_venue_latlng() (docs) to check if it has a latitude/longtitude set.
    • If it has, skip it. Otherwise, get the address (this will be array) via eo_get_venue_address()(docs).
    • Using the address, use the above Geocoder (or an alternative) to retrieve a lat/lng co-ordinate for the venue.
    • Update the venue as follows:

      eo_update_venue( $venue_id, array(
          'latitude' => $latitude,
          'longtitude' => $longtitude,
      ) );
      

    (see docs: http://codex.wp-event-organiser.com/function-eo_update_venue.html)

    You could alternatively adapt the command you’ve linked to, and update the venue with the lat/lng co-ordinates immediately after creating it (and deleting all your current venues)

    Stephen Harris
    #27903

    Many thanks for your reply Stephen.

    I actually solved the issue after making the post by modifying the file at https://gist.github.com/stephenharris/00a6a601b274b38a59cc82c146a95688

    I made a cURL request before inserting the venue to Google Maps, and parsed the response to find the lat / long and then added the lat and long to the $venue variable. Here’s the modified file in case someone needs the same thing.

    https://gist.github.com/SadikBhimani/3efd92dbb503d98c0253e6fe1556d8e1

    Best Regards, – Sadik

    • This reply was modified 6 years, 9 months ago by  Sadik Bhimani.
    Sadik Bhimani
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.