Created
September 9, 2017 07:11
-
-
Save wpflippercode/c920b59f4eee6c8edead58a2c96dd5c5 to your computer and use it in GitHub Desktop.
Show Markers on the Google Maps Using Remote JSON File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('wpgmp_marker_source','wpgmp_marker_source',1,2); | |
function wpgmp_marker_source($markers,$map_id) { | |
/* You can create array of the markers to add on the google maps dynamically. It's very useful hook if you want to fetch | |
locations from an external database, API, JSON or XML. | |
*/ | |
$markers = array(); | |
$json_entries = wp_remote_get('https://www.flippercode.com/sample_markers.json'); | |
$array_entries = json_decode($json_entries['body'], true); | |
if(!empty($array_entries)) { | |
// Loop Start Here... | |
foreach($array_entries as $key => $entry) { | |
if($key == 0 ) { | |
continue; //Skip header column in the csv. | |
} | |
$marker = array(); | |
$marker['title'] = $entry[0]; // Assign a title to the marker. | |
$marker['address'] = $entry[1]; // Assign an address to the marker. | |
$marker['latitude'] =$entry[2]; // Assign latitude to the marker. | |
$marker['longitude'] =$entry[3]; // Assign longitude to the marker. | |
$marker['message'] =$entry[4]; // Show Infowindow message on marker click. | |
$markers[] = $marker; | |
} | |
// Loop ended Here... | |
} | |
return $markers; // Return array of markers. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment