Hello @maryboki,
What exactly would you like to do with the current location coords? Display them in the current location widget/shortcode or use them with other functions?
Right now I just want to display them via the shortcode. Thanks!
OK.
Which elements are you currently displaying using the Current Location ( map, address, username… )?
Are you using the widget or the shortcode?
I’m using the shortcode: [gmw_current_location address_fields=”street,city” zoom_level=”18″ location_form_trigger=”Get your current location”]
So it shows their name, street and city along with a zoomed in map.
What I want is to have an additional option for address_fields that returns the coordinates also i.e. address_fields=”street,city,coords”
Basically this location info returned from https://maps.googleapis.com/maps/api/geocode/
<geometry>
<location>
<lat>37.4223096</lat>
<lng>-122.0846244</lng>
</location>
Thanks!
@maryboki,
Using the shortcode attribute address_fields=”street,city,lat,lng” should display the coordinates. However, it will display the coords as part of the address field, since at the moment, the shortcode is not meant to display the coords.
Instead, you can use the below script as a work-around:
function gmw_cl_display_coordinates( $output, $args, $user_position ) {
// Abort if coords are missing.
if ( empty( $user_position['lat'] ) || empty( $user_position['lng'] ) ) {
return $output;
}
$output .= '<div class="gmw-cl-element gmw-cl-coords-wrapper">';
$output .= '<lat>' . esc_attr( $user_position['lat'] ) . '</lat><lng>' . esc_attr( $user_position['lng'] ) . '</lng>';
$output .= '</div>';
return $output;
}
add_filter( 'gmw_current_location_address', 'gmw_cl_display_coordinates', 50, 3 );
I hope this helps.