Description
Geocode the given address to return the lat and long
Usage
$array = bw_geocode_googlemap( $input );Parameters
- $input
- ( array ) required – { Array of parameters
- extended-address
- ( string ) required – Extended address
- street-address
- ( string ) required – Street address
- locality
- ( string ) required – Locality
- region
- ( string ) required – Region
- postal-code
- ( string ) required – Post code or ZIP code
- country-name
- ( string ) required – Country name or abbreviation
- lat
- ( string ) required – latitude in decimal format
- long
- ( string ) required – longitude in decimal format }
Returns
array the updated input arraySource
File name: oik/shortcodes/oik-googlemap.phpLines:
1 to 37 of 37
function bw_geocode_googlemap( $input ) { $extended_address = bw_array_get( $input, 'extended-address', "" ); $street_address = bw_array_get( $input, 'street-address', "" ); $locality = bw_array_get( $input, 'locality', "" ); $region = bw_array_get( $input, 'region', "" ); $postal_code = bw_array_get( $input, 'postal-code', "" ); $country_name = bw_array_get( $input, 'country-name', "" ); $address = bw_append( $extended_address, null ); $address .= bw_append( $street_address ); $address .= bw_append( $locality ); $address .= bw_append( $region ); $address .= bw_append( $postal_code ); $address .= bw_append( $country_name ); $address = urlencode( $address ); if ( $address ) { $map_url = "https://maps.google.com/maps/api/geocode/json?sensor=false"; $map_url .= str_replace( "&", "&", bw_gmap_api_key() ); $map_url .= "&address="; // Google's documentation recommends using JSON since it's smaller than the XML output. // $map_url = "http://maps.google.com/maps/api/geocode/xml?sensor=false&address="; $map_url .= $address; oik_require( "includes/oik-remote.inc" ); $json = bw_remote_get( $map_url ); bw_trace2( $json, "json", true, BW_TRACE_DEBUG ); if ( $json ) { $input = bw_set_geocoded_address( $input, $json ); } } return( $input ); }View on GitHub View on Trac
Invoked by
Calls
1 to 5 of 5
- bw_append() – Return a non null string following the separator or null
- bw_array_get() – Return the array[index] or array->index (for an object) or a default value if not set
- bw_remote_get() – Wrapper to wp_remote_get
- bw_set_geocoded_address() – Update the input to the geocoded address
- oik_require() – Invoke require_once on an oik include file or other file
