REST API endpoint for venue latitude/longitude

Home Forums Calendar Products Events Calendar PRO REST API endpoint for venue latitude/longitude

  • This topic has 3 replies, 4 voices, and was last updated 9 years ago by Kalle.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1249616
    Kalle
    Participant

    Hello,

    I’m feeding TEC events and venues into my native Android app with WP REST API, however I still have not been able to get the venue lat/lng data as an endpoint.

    In otherwords: In PHP, given just venue ID, how can I get venue latitude and longitude?

    SOLVED: As I wrote this post, came up with a solution:

    My query: http://www.mywebsite.com/wp-json/wp/v2/tribe_venue?per_page=100&fields=id,title.rendered,city,address,latlng&order=asc

    Endpoint code from my theme’s functions.php (code below is just for the lat/lng part of my query):

    add_action( 'rest_api_init', 'slug_register_venue_latlng' );
    
    function slug_register_venue_latlng() {
    	register_rest_field( 'tribe_venue','latlng',
    		array(
    			'get_callback'    => 'slug_get_venue_latlng',
    			'schema'          => null
    		)
    	);
    }
    
    function slug_get_venue_latlng( $object, $field_name, $request ) {
    
    	$postId = $object[ 'id' ];
    
            // Check if lat/lng exists for the venue post, otherwise, use zero.
    	if ( class_exists( 'Tribe__Events__Pro__Geo_Loc' ) ) {
    		$output[ 'lat' ] = (float) get_post_meta( $postId, Tribe__Events__Pro__Geo_Loc::LAT, true );
    		$output[ 'lng' ] = (float) get_post_meta( $postId, Tribe__Events__Pro__Geo_Loc::LNG, true );
    	} else {
    		$output = array(
    			'lat' => 0,
    			'lng' => 0
    		);
    	}
    	return $output;
    }
    #1250264
    George
    Participant

    Thanks for sharing your solution! REST API support is not something we’ve fully rolled out—support should be arriving in version 4.5, if all goes to plan (though this is subject to change).

    Best of luck with your current solution in the meantime!

    Open a new thread any time if other issues or questions arise.

    — George

    #1260954
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘REST API endpoint for venue latitude/longitude’ is closed to new replies.