Hello!
I am using the map field in a front-end posting, where users can add auto listing.
They are required to choose an address by placing a pin on the map, or typing the adress.
I managed to get the map to show up in single listing, and by using the bellow code, i can echo the city name as text :
function location_shortcode( $atts ) {
extract( shortcode_atts(
array(
‘id’ => ”,
), $atts )
);
if ( isset( $id ) && get_field(‘loc_de_intalnire’, $id) ) {
$google_map = get_field(‘loc_de_intalnire’, $id);
$url = ‘https://maps.googleapis.com/maps/api/geocode/json?latlng=’.$google_map[‘lat’].’,’.$google_map[‘lng’].’&sensor=true’;
$data = @file_get_contents($url);
$jsondata = json_decode($data,true);
if(is_array($jsondata) && $jsondata[‘status’] == “OK”)
{
// city
foreach ($jsondata[“results”] as $result) {
foreach ($result[“address_components”] as $address) {
if (in_array(“locality”, $address[“types”])) {
$city = $address[“long_name”];
}
}
}
}
$location = $city;
return $location;
}
}
add_shortcode( ‘location’, ‘location_shortcode’ );
I would like to make a search form, where users can search for the city,like this:
<label>City</label>
<select>
<option value=\”” . $city . “\”>” . $city . “</option>
</select>
Can anyone help me achieve that?
Thank you for trying!