WordPress PHP массив в массив JS для использования в карте GooglePhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 WordPress PHP массив в массив JS для использования в карте Google

Сообщение Anonymous »

Привет, я хочу использовать некоторые данные, хранящиеся в массиве PHP для использования в API Google Map, для заполнения нескольких местоположений в карте.

$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>
Если я print_r ($ locations_array) я получаю это. < /p>
print_r($locations_array); // to see the contents
< /code>
Результат: < /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>
Я хочу использовать эти данные в API Google Map. Я создаю этот файл map.js < /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[1], locations[2]),
map: map,
clickable: true,
url:locations[4]
});

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

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


Подробнее здесь: https://stackoverflow.com/questions/355 ... google-map
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»