WordPress PHP -Array zum JS -Array, um sie in Google Map zu verwendenPhp

PHP-Programmierer chatten hier
Anonymous
 WordPress PHP -Array zum JS -Array, um sie in Google Map zu verwenden

Post by Anonymous »

Hallo, ich möchte einige Daten verwenden, die in einem PHP -Array gespeichert sind, um es in der Google Map -API zu verwenden, um mehrere Positionen in einer Karte zu füllen.

Code: Select all


$locations_data = array(get_the_title(), rwmb_meta( 'lat' ), rwmb_meta( 'lng' ), get_the_ID (), get_permalink());
array_push($locations_array, $locations_data);

endwhile;
< /code>
Wenn ich drucke ($ popals_array) Ich bekomme das. < /p>
print_r($locations_array); // to see the contents
< /code>
Ergebnis: < /p>
Array ( [0] => Array ( [0] => title 1 [1] => -54.8949292 [2] => -56.1682769 [3] => 3175 [4] => http://localhost/wordpress/custom_post/title1/ ) [1] => Array ( [0] => title 2 [1] => -54.8617426 [2] => -56.1998983 [3] => 3174 [4] => http://localhost/wordpress/custom_post/title2/ ) [2] => Array ( [0] => title 3 [1] => -54.8617426 [2] => -56.1998983 [3] => 3169 [4] => http://localhost/wordpress/custom_post/title3/ ) )
< /code>
Ich möchte diese Daten in der Google Map -API verwenden. Ich erstelle diese map.js -Datei < /p>
jQuery('document').ready(function($){
'use strict';
// Google Maps

function init() {
// ***HERE I NEED TO PUT MY DATA***
var locations = [
['title 1', -54.89942324, -56.13500564, "the_ID_of_title1","the permalink of title1"],
['title 2', -54.90618086, -56.17895096, "the_ID_of _title2","the permalink of title2"],
['title 3', -54.89379148, -56.1645314, "the_ID_of title3","the permalink of title3"],
];

var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: new google.maps.LatLng(-54.85492175, -56.16659134),
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var infowindow = new google.maps.InfoWindow();

var marker, i;

for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
clickable: true,
url:locations[i][4]
});

google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
window.location.href = marker.url;
}
})(marker, i));
}
}

google.maps.event.addDomListener(window, 'load', init);
});

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post