Using Google Maps v3, PHP and Json to plot markers
Posted
by bateman_ap
on Stack Overflow
See other posts from Stack Overflow
or by bateman_ap
Published on 2010-04-12T21:23:51Z
Indexed on
2010/04/12
23:33 UTC
Read the original article
Hit count: 763
Hi, I am creating a map using the new(ish) v3 of the Google Maps API
I have managed to get a map displaying using code as below:
var myLatlng = new google.maps.LatLng(50.8194000,-0.1363000);
var myOptions = {
zoom: 14,
center: myLatlng,
mapTypeControl: false,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("location-map"), myOptions);
However I now want to add a number of markers I have stored in a PHP array.
The Array currently looks like this if I print it out to screen:
Array
(
[0] => Array
(
[poiUid] => 20
[poiName] => Brighton Cineworld
[poiCode] => brighton-cineworld
[poiLon] => -0.100450
[poiLat] => 50.810780
[poiType] => Cinemas
)
[1] => Array
(
[poiUid] => 21
[poiName] => Brighton Odeon
[poiCode] => brighton-odeon
[poiLon] => -0.144420
[poiLat] => 50.821860
[poiType] => Cinemas
)
)
All the reading I have done so far suggests I turn this into JSON by using json_encode
If I run the Array though this and echo it to the screen I get:
[{"poiUid":"20","poiName":"Brighton Cineworld","poiCode":"brighton-cineworld","poiLon":"-0.100450","poiLat":"50.810780","poiType":"Cinemas"},{"poiUid":"21","poiName":"Brighton Odeon","poiCode":"brighton-odeon","poiLon":"-0.144420","poiLat":"50.821860","poiType":"Cinemas"}]
The bit now is where I am struggling, I am not sure the encoded array is what I need to start populating markers, I think I need something like the code below but not sure how to add the markers from my passed through JSON
var locations = $jsonPoiArray;
for (var i = 0;i < locations.length; i += 1) {
// Create a new marker
};
© Stack Overflow or respective owner