I'm trying to add some Markers on Google Map but before I do this I need to unset some elements of JSON Array which I'm doing like this
$json = str_replace('"', '"', $loc);
foreach ($json as $key => $value)
{
if(preg_match('/^[X]{2}/',$value['pname'])){
unset($json[$key]);
}
}
echo json_encode($json);
before the unset this is how it displays in JS console.log() and plots the Markers
[Object, Object, Object, Object,...]
but after the unset it displays like this and does NOT plot the Markers
Object {2: Object, 20: Object, 40: Object,...}
Can anyone put me in right direction please.
This is the code that produces Markers on Google maps.
makeRequest('get_locations.php', function(data) {
var data = JSON.parse(data.responseText);
for (var i = 0; i < data.length; i++) {
displayResellersPostCode(data[i]);
}
});
function displayResellersPostCode(location) {
if (parseInt(location.lat) == 0) {
geocoder.geocode( { 'pcode1': location.pcode1 }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: location.uname
});
}
});
} else {
var position = new google.maps.LatLng(parseFloat(location.latitude), parseFloat(location.longitude));
var marker = new google.maps.Marker({
map: map,
position: position,
title: location.uname
});
}
}
0 comments:
Post a Comment