Bird
0
0

You want to display a Google Map field from ACF with a marker on the map. Which of these is the correct way to get the map data and print the latitude?

hard📝 Application Q9 of 15
Wordpress - Custom Fields and Meta Data
You want to display a Google Map field from ACF with a marker on the map. Which of these is the correct way to get the map data and print the latitude?
A$map = get_field('location_map');<br>echo $map->lat;
B$map = get_field('location_map');<br>echo $map->latitude;
C$map = get_field('location_map');<br>echo $map['latitude'];
D$map = get_field('location_map');<br>echo $map['lat'];
Step-by-Step Solution
Solution:
  1. Step 1: Know the Google Map field returns an array

    ACF returns map data as an associative array with keys 'lat' and 'lng'.
  2. Step 2: Access latitude using array key 'lat'

    Use $map['lat'] to get latitude value.
  3. Final Answer:

    $map = get_field('location_map'); echo $map['lat']; -> Option D
  4. Quick Check:

    Google Map lat = $map['lat'] [OK]
Quick Trick: Google Map field returns array with 'lat' and 'lng' keys [OK]
Common Mistakes:
  • Using object property syntax instead of array
  • Using 'latitude' key instead of 'lat'
  • Assuming map field returns string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes