Custom Google Makers with DataLayer/GeoJson - php

I'm currently having an Issue getting google markers to display custom images depending on the type. I have had it working in the past that only had one image for all the markers.
map.php
var map,
infoWindow = new google.maps.InfoWindow({pixelOffset: new google.maps.Size(0,-25)});
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 12,
center: {lat: 53.927895, lng: -1.386487}
});
map.data.loadGeoJson('http://customers.auroracomputers.co.uk/customers-json.php');
map.data.addListener('click', function(event) {
infoWindow.setContent(
'Surname: ' + event.feature.getProperty('surname') + '<br>' +
'Postcode: ' + event.feature.getProperty('postcode')
);
var anchor = new google.maps.MVCObject();
anchor.set("position",event.latLng);
infoWindow.open(map,anchor);
});
var iconBase = 'http://customers.auroracomputers.co.uk/icons/'
var icons = {
business: {
icon: iconBase + 'business.png'
},
home: {
icon: iconBase + 'home.png'
},
competitor: {
icon: iconBase + 'devil.png'
}
};
function addMarker(feature) {
var marker = new google.maps.Marker({
position: feature.position,
icon: icons[feature.type].icon,
map: map
});
}
map.data.setStyle({
icon: 'http://customers.auroracomputers.co.uk/icons/home.png',
icon: icons[feature.type].icon,
icon: icon.competitor.icon
});
}
google.maps.event.addDomListener(window, 'load', initialize);
Customer-Json.php
for ($i=0;$i<$nrows;$i++){
$row = mysqli_fetch_assoc($result);
?>
<script>
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [<?echo $row['lng'];?>,<?echo $row['lat'];?>]
},
"properties": {
"surname": "<?echo $row['surname'];?>",
"postcode": "<?echo $row['postcode'];?>",
"type": "<?echo $row['type'];?>"
}
}<?php if( $i != $nrows-1 ){ ?>,<?php } ?>
</script>

GeoJson markers are styled differently than native Google Maps Javascript API v3 markers. See Style GeoJSON Data in the documentation, in particular the section on Change Appearance Dynamically.
map.data.setStyle(function(feature) {
var type = feature.getProperty('type')
return /** #type {google.maps.Data.StyleOptions} */ ({
icon: icons[type].icon,
title: type
});
});
from the reference:
icon Type: string|Icon|Symbol
Icon for the foreground. If a string is provided, it is treated as though it were an Icon with the string as url. Only applies to point geometries.
proof of concept fiddle
code snippet:
var map,
infoWindow = new google.maps.InfoWindow({
pixelOffset: new google.maps.Size(0, -25)
});
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 10,
center: {
lat: 40.7127837,
lng: -74.0059413
}
});
// map.data.loadGeoJson('http://customers.auroracomputers.co.uk/customers-json.php');
map.data.addGeoJson(testGeoJson)
map.data.addListener('click', function(event) {
infoWindow.setContent(
'Surname: ' + event.feature.getProperty('surname') + '<br>' +
'Postcode: ' + event.feature.getProperty('postcode')
);
var anchor = new google.maps.MVCObject();
anchor.set("position", event.latLng);
infoWindow.open(map, anchor);
});
var iconBase = 'http://customers.auroracomputers.co.uk/icons/'
var icons = {
business: {
icon: iconBase + 'business.png'
},
home: {
icon: iconBase + 'home.png'
},
competitor: {
icon: iconBase + 'devil.png'
}
};
map.data.setStyle(function(feature) {
var type = feature.getProperty('type')
return /** #type {google.maps.Data.StyleOptions} */ ({
icon: icons[type].icon,
title: type
});
});
}
google.maps.event.addDomListener(window, 'load', initialize);
// New York, NY, USA (40.7127837, -74.00594130000002)
// Newark, NJ, USA (40.735657, -74.1723667)
var testGeoJson = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-74.0059413, 40.7127837]
},
"properties": {
"surname": "York",
"postcode": " 10007",
"type": "home"
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-74.1723667, 40.735657]
},
"properties": {
"surname": "Newark",
"postcode": "07102",
"type": "business"
}
}]
};
html,
body,
#map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map-canvas"></div>

One thing I note is the source json is corrupted, hopefully the following might help get that sorted.
<?php
/*
Customer-Json.php
-----------------
The original code had thousands of `<script>` & `</script>` tags
which meant it was not valid json.
I have assumed that the previous loop can be replaced with the
more usual recordset iteration loop as shown below.
Each row has items added to the json array which gets echoed at the
end - there is not need for the script tags at all - just include the
correct headers.
*/
/* store data to be sent */
$json=array();
/* using object notation for ease */
while( $row=mysqli_fetch_object( $result ) ){
$surname=$row->surname;
$postcode=$row->postcode;
$lat=$row->lat;
$lng=$row->lng;
$type=$row->type;
$json[]=array(
'type' => 'Feature',
'geometry' => array(
'type' => 'Point',
'coordinates' => array( $lng, $lat )
),
'properties' => array(
'surname' => $surname,
'postcode' => $postcode,
'type' => $type
)
);
}
$json=json_encode( $json );
header( 'Content-Type: application/json' );
echo $json;
?>

Related

how to display data on google map info window from database using php mysqli

my sql query to fetch state count and state name that give me count and name of the state.
my problem is that i wanted to display multiple markers on google map from database. I need to display the data on click of marker on info window at google map im trying following code.
I'm not able to understand how to add loop in data.addRows.
or please let me know where I'm doing wrong
$sql = "SELECT `state`, COUNT(DISTINCT `sr_no`) AS `stateno`
FROM `Mystate` GROUP BY `state`";
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {
'packages': ['map'],
// Note: you will need to get a mapsApiKey for your project.
// See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
'mapsApiKey': 'API_KEY'
});
google.charts.setOnLoadCallback(drawMap);
function drawMap () {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Address');
data.addColumn('string', 'Location');
data.addColumn('string', 'Marker')
data.addRows([
['Mumbai, Maharashtra', 'India', 'blue' ],
['Pune, Maharashtra', 'India', 'green']
]);
var url = 'https://icons.iconarchive.com/icons/icons-land/vista-map-markers/48/';
var options = {
center: { lat: 20.5937, lng: 78.9629 },
zoomLevel: 5,
showTooltip: true,
showInfoWindow: true,
useMapTypeControl: true,
icons: {
blue: {
normal: url + 'Map-Marker-Ball-Azure-icon.png',
selected: url + 'Map-Marker-Ball-Right-Azure-icon.png'
},
green: {
normal: url + 'Map-Marker-Push-Pin-1-Chartreuse-icon.png',
selected: url + 'Map-Marker-Push-Pin-1-Right-Chartreuse-icon.png'
},
pink: {
normal: url + 'Map-Marker-Ball-Pink-icon.png',
selected: url + 'Map-Marker-Ball-Right-Pink-icon.png'
}
}
};
var map = new google.visualization.Map(document.getElementById('map_div'));
map.draw(data, options);
}
</script>
</head>
<body>
<div id="map_div" style="height: 600px; width: 900px"></div>
</body>
</html>
It is not clear how you hope to select the colour of the marker, nor what you actually do with the stateno from the SQL query. That said, the JSON deata in the following is from one of my old databases and was used to emulate what your query might return. The actual task of processing this recordset and adding the data to the dataTable is done with an Object.keys( json ).forEach loop.
ie:
Object.keys( json ).forEach( key=>{
let obj=json[ key ];
data.addRow([
obj.state, 'India', 'green'
]);
})
The full, working example with a hardcoded valud of green for the marker. I would suggest that this colour could be determined by the stateno data as that is not used but nothing in the above supports that. If that were the case a simple lookup of the stateno number against some sort of matrix of value/colour could be done.
I should possibly warn that running and testing this multiple times could lead to charges being raised against your apikey because of the need for each marker location needing to be geocoded in order to find the location.
<html>
<head>
<script src='https://www.gstatic.com/charts/loader.js'></script>
<script>
const json=[
{
"state":"Andaman and Nicobar Islands",
"stateno":"1"
},
{
"state":"Andhra Pradesh",
"stateno":"104"
},
{
"state":"Arunachal Pradesh",
"stateno":"1"
},
{
"state":"Assam",
"stateno":"15"
},
{
"state":"Bihar",
"stateno":"46"
},
{
"state":"Chandigarh",
"stateno":"1"
},
{
"state":"Chhattisgarh",
"stateno":"12"
},
{
"state":"Delhi",
"stateno":"29"
},
{
"state":"Goa",
"stateno":"3"
},
{
"state":"Gujarat",
"stateno":"63"
},
{
"state":"Haryana",
"stateno":"26"
},
{
"state":"Himachal Pradesh",
"stateno":"1"
},
{
"state":"Jammu and Kashmir",
"stateno":"8"
},
{
"state":"Jharkhand",
"stateno":"23"
},
{
"state":"Karnataka",
"stateno":"65"
},
{
"state":"Kerala",
"stateno":"32"
},
{
"state":"Madhya Pradesh",
"stateno":"53"
},
{
"state":"Maharashtra",
"stateno":"90"
},
{
"state":"Manipur",
"stateno":"1"
},
{
"state":"Meghalaya",
"stateno":"2"
},
{
"state":"Mizoram",
"stateno":"2"
},
{
"state":"Nagaland",
"stateno":"3"
},
{
"state":"Orissa",
"stateno":"22"
},
{
"state":"Pondicherry",
"stateno":"3"
},
{
"state":"Punjab",
"stateno":"34"
},
{
"state":"Rajasthan",
"stateno":"50"
},
{
"state":"Tamil Nadu",
"stateno":"85"
},
{
"state":"Tripura",
"stateno":"3"
},
{
"state":"Uttar Pradesh",
"stateno":"119"
},
{
"state":"West Bengal",
"stateno":"93"
}
];
google.charts.load('current', {
'packages': ['map'],
'mapsApiKey': 'AIzaSy..................04......tA'
});
google.charts.setOnLoadCallback(drawMap);
function drawMap () {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Address');
data.addColumn('string', 'Location');
data.addColumn('string', 'Marker');
/*
data.addRows([
['Mumbai, Maharashtra', 'India', 'blue' ],
['Pune, Maharashtra', 'India', 'green']
]);
*/
Object.keys( json ).forEach( key=>{
let obj=json[ key ];
data.addRow([
obj.state, 'India', 'green'
]);
})
var url = 'https://icons.iconarchive.com/icons/icons-land/vista-map-markers/48/';
var options = {
center: { lat: 20.5937, lng: 78.9629 },
zoomLevel: 5,
showTooltip: true,
showInfoWindow: true,
useMapTypeControl: true,
icons: {
blue: {
normal: url + 'Map-Marker-Ball-Azure-icon.png',
selected: url + 'Map-Marker-Ball-Right-Azure-icon.png'
},
green: {
normal: url + 'Map-Marker-Push-Pin-1-Chartreuse-icon.png',
selected: url + 'Map-Marker-Push-Pin-1-Right-Chartreuse-icon.png'
},
pink: {
normal: url + 'Map-Marker-Ball-Pink-icon.png',
selected: url + 'Map-Marker-Ball-Right-Pink-icon.png'
}
}
};
var map = new google.visualization.Map(document.getElementById('map_div'));
map.draw(data, options);
}
</script>
</head>
<body>
<div id='map_div' style='height: 600px; width: 900px'></div>
</body>
</html>
update
Following on from comments about infoWindows etc I modified the working code I had to perform the lookup and return a different colour icon based upon arbitrary figures ( edit as appropriate if applicable ) and modified the data being added to the dataTable so that the 2nd argument contains the name & count - when the marker is clicked that will be displayed in the tooltip/infoWindow
const matrix={
0:'blue',
30:'green',
75:'pink'
};
const lookup=(i)=>{
let icon=false;
Object.keys( matrix ).forEach( key=>{
if( i > key ) icon=matrix[ key ];
});
return icon
};
Object.keys( json ).forEach( key=>{
let obj=json[ key ];
let icon=lookup( obj.stateno );
data.addRow([
obj.state, `${obj.state} - Count: ${obj.stateno}`, icon
])
});

How to show values on pie or bar graph chart in php using chart.js

I want to show values on graphs. i search alot but could not find my solution.
Here is the code below:
<script>
var ctx = document.getElementById("barChart");
ctx.height = 100;
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: <?php echo json_encode($Division); ?>,
datasets: [{
label: 'Target',
data: <?php echo json_encode($TARGET_QTY); ?>,
//backgroundColor: "rgba(255, 159, 64, 0.2)",
backgroundColor: "rgb(231, 123, 126)",
borderColor: "rgb(219, 219, 219)",
borderWidth: 1
},
{
label: 'Actual',
data: <?php echo json_encode($DISPATCH_QTY); ?>,
backgroundColor: "rgb(0, 191, 255)",
borderColor: "rgb(252, 252, 252)",
borderWidth: 1
}
]
},
options: {
responsive: true,
tooltips: {
"enabled": false
},
scales: {
yAxes: [{
gridLines: {
display:false,
},
ticks: {
beginAtZero:true
}
}]
},
title: {
display: true,
// position:"bottom",
text: 'Target vs Actual Dispatch'
},
hover: {
// Overrides the global setting
mode: 'label'
},
animation: {
duration: 1,
onComplete: function () {
var chartInstance = this.chart,
ctx = chartInstance.ctx;
ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontSize, Chart.defaults.global.defaultFontStyle, Chart.defaults.global.defaultFontFamily);
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
this.data.datasets.forEach(function (dataset, i)
{
var meta = chartInstance.controller.getDatasetMeta(i);
meta.data.forEach(function (bar, index) {
var data = dataset.data[index];
ctx.fillText(data, bar._model.x, bar._model.y - 5);
});
});
}
},
/*legend: {
display: true,
// position : "bottom",
labels: {
fontColor: 'rgb(0, 0, 0)'
}
}*/
}
});
</script>
<div class="row">
<div class="col-md-12">
<div class="chart">
<canvas id="barChart" style="position: relative; height: 300px;"></canvas>
</div>
</div>
</div>
I search alot but could not show values in the bar graph. In this code value will be shown on the top of the graph but could not show on the bar. i want to show value on the bars of graph. either its a bar chart or pie chart. i use chart.js library. Please help me to get rid of this situation. Thanks in Advance.

How can we replace A,B,C .. to 1 ,2,3.. in waypoints Google map API?

We need some help. We have below Google Map code which is working fine. Only thing is we need to customise the text in waypoints to integer.Will it be possible?
This is how we want : http://screencast.com/t/TKFOAB7UQ
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps API</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js? sensor=false&libraries=places"></script>
</head>
<body style="font-family: Arial; font-size: 12px;">
<div style="width: 100%">
<div id="map-canvas" style="width: 950px; height: 400px; float: left;"></div>
<div id="panel" style="width: 300px; float: left;"></div>
</div>
<script type="text/javascript">
function initialize() {
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: [ { featureType:'water', stylers:[{color:'#46bcec'},{visibility:'on'}] },{ featureType:'landscape', stylers:[{color:'#f2f2f2'}] },{ featureType:'road', stylers: [{saturation:-100},{lightness:45}] },{ featureType:'road.highway', stylers: [{visibility:'simplified'}] },{ featureType:'road.arterial', elementType:'labels.icon', stylers: [{visibility:'off'}] },{ featureType:'administrative', elementType:'labels.text.fill', stylers: [{color:'#444444'}] },{ featureType:'transit', stylers:[{visibility:'off'}] },{ featureType:'poi', stylers:[{visibility:'off'}] }],
});
directionsDisplay.setMap(map);
// directionsDisplay.setPanel(document.getElementById('panel'));
var waypts = [{location:new google.maps.LatLng(1.33202, 103.67673), stopover:true}, { location:new google.maps.LatLng(1.29418, 103.84943), stopover:true}];
var request = {
origin: new google.maps.LatLng(1.25675, 103.82033),
destination: new google.maps.LatLng(1.28627, 103.85927),
waypoints: waypts,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
initialize();
</script>
</body>
</html>
What you can do, is not display the markers with letters and make your own.
Here is an example.
Look at my
- line 4: suppressMarkers : true
- line 40: here you can also change the color of the icon. Look at the link for more info.
function initialize() {
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer({
suppressMarkers : true
});
var map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: [ { featureType:'water', stylers:[{color:'#46bcec'},{visibility:'on'}] },{ featureType:'landscape', stylers:[{color:'#f2f2f2'}] },{ featureType:'road', stylers: [{saturation:-100},{lightness:45}] },{ featureType:'road.highway', stylers: [{visibility:'simplified'}] },{ featureType:'road.arterial', elementType:'labels.icon', stylers: [{visibility:'off'}] },{ featureType:'administrative', elementType:'labels.text.fill', stylers: [{color:'#444444'}] },{ featureType:'transit', stylers:[{visibility:'off'}] },{ featureType:'poi', stylers:[{visibility:'off'}] }],
});
directionsDisplay.setMap(map);
// directionsDisplay.setPanel(document.getElementById('panel'));
var waypts = [
{location:new google.maps.LatLng(1.33202, 103.67673), stopover:true},
{location:new google.maps.LatLng(1.29418, 103.84943), stopover:true}
];
var request = {
origin: new google.maps.LatLng(1.25675, 103.82033),
destination: new google.maps.LatLng(1.28627, 103.85927),
waypoints: waypts,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var markerCounter = 1;
directionsDisplay.setDirections(response);
// add custom markers
var route = response.routes[0];
// start marker
addMarker(route.legs[0].start_location, markerCounter++);
// the rest
for (var i = 0; i < route.legs.length; i++) {
addMarker(route.legs[i].end_location, markerCounter++);
}
}
});
function addMarker(position, i) {
return new google.maps.Marker({
// #see http://stackoverflow.com/questions/2436484/how-can-i-create-numbered-map-markers-in-google-maps-v3 for numbered icons
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + i + '|FF0000|000000',
position: position,
map: map
})
}
}
google.maps.event.addDomListener(window, 'load', initialize);

Multiple series, multiple charts Highcharts

i have to create a single chart showing different series with different type of chart (Ex: one data series with 'areaspline' and one data series with 'column'). I built a db with a lot of data, extracted by sql query into a json file
[
{ "name": "Test", "data": [2.8,2.8,2.8,2.7,2.7,] },
{ "name": "kwc", "data": [10,1,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] }
]
The json file is correct, but if i try to select the series for a chart with the $.each function it doesn't work!
Here's my code
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script src="estrazione.php"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$.getJSON("new3.php", function(json) {
$.each(json.data, function(index, item){
// split the data set into ohlc and volume
var temperatura = [],
misura = [],
dataLength = json.length;
for (i = 0; i < dataLength; i++) {
temperatura.push([
data[i][0]
]);
misura.push([
data[i][1]
])
}
$('#container').highcharts({
chart: {
zoomType: 'xy'
},
title: {
text: 'Analisi Temperature e Consumo Generale',
},
xAxis: [{
categories: ['00.00', '00.15', '00.30', '00.45', '01.00', '01.15', '01.30', '01.45', '02.00', '02.15', '02.30', '02.45', '03.00', '03.15', '03.30', '03.45', '04.00', '04.15', '04.30', '04.45', '05.00', '05.15', '05.30', '05.45', '06.00', '06.15', '06.30', '06.45', '07.00', '07.15', '07.30', '07.45', '08.00', '08.15', '08.30', '08.45', '09.00', '09.15', '09.30', '09.45', '10.00', '10.15', '10.30', '10.45', '11.00', '11.15', '11.30', '11.45', '12.00', '12.15', '12.30', '12.45', '13.00', '13.15', '13.30', '13.45', '14.00', '14.15', '14.30', '14.45', '15.00', '15.15', '15.30', '15.45', '16.00', '16.15', '16.30', '16.45', '17.00', '17.15', '17.30', '17.45', '18.00', '18.15', '18.30', '18.45', '19.00', '19.15', '19.30', '19.45', '20.00', '20.15', '20.30', '20.45', '21.00', '21.15', '21.30', '21.45', '22.00', '22.15', '22.30', '22.45', '23.00', '23.15', '23.30', '23.45'],
}],
yAxis: [{ // Primary yAxis
labels: {
format: '{value}°C',
style: {
color: '#89A54E'
}
},
title: {
text: 'Temperature',
style: {
color: '#89A54E'
}
}
}, { // Secondary yAxis
title: {
text: 'Consumo',
style: {
color: '#4572A7'
}
},
labels: {
format: '{value} Kw',
style: {
color: '#4572A7'
}
},
opposite: true
}],
tooltip: {
shared: true
},
legend: {
layout: 'vertical',
align: 'left',
x: 120,
verticalAlign: 'top',
y: 100,
floating: true,
backgroundColor: '#FFFFFF'
},
series: [{
name: 'Misure',
color: '#4572A7',
type: 'column',
yAxis: 1,
data: misura,
tooltip: {
valueSuffix: ' Kw'
}
}, {
name: 'Temperature',
color: '#89A54E',
type: 'spline',
data: temperatura,
tooltip: {
valueSuffix: '°C'
}
}]
});
});
</script>
</head>
<body>
<script src="js/highcharts.js"></script>
<script src="js/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</body>
</html>'
this is my php code:
<?php
$data_scelta = "2013-08-08";
$misura = "kwc";
$temperatura = "Test";
$link = mysqli_connect('localhost:3306', 'root', '','telegestione');
if (!$link) {
die('Could not connect: ' . mysqli_error());}
$sth = mysqli_query($link,"SELECT $temperatura FROM temperature WHERE dataora BETWEEN '$data_scelta 00:00:00.000'
AND '$data_scelta 23:59:59.997'");
$rows = array();
$rows['name'] = $temperatura;
while($r = mysqli_fetch_assoc($sth)) {
$rows['data'][] = $r[$temperatura];}
$sth = mysqli_query($link,"SELECT $misura FROM misure WHERE dataora BETWEEN '$data_scelta 00:00:00.000'
AND '$data_scelta 23:59:59.997'");
$rows1 = array();
$rows1['name'] = $misura;
while($rr = mysqli_fetch_assoc($sth)) {
$rows1['data'][] = $rr[$misura];}
$result = array();
array_push($result,$rows);
array_push($result,$rows1);
print json_encode($result, JSON_NUMERIC_CHECK);
?>
I tryed any kind of option, but anything gone right :(
Any hope to display 1 chart, 2 or more data series and 2 or more type of charts?
Thanks in advance
It looks like your highcharts creation call is within your $.each function. So it will try to create 2 highcharts, but they both will be created in the same div, so you'll only end up with one.
Also, the way you are caculating datalength, it'll be 2. When, it appears, you'd like it to be the length of the actual data (which is different for your different series).
I can't do the getJSON in a jsfiddle, so I'm assuming your PHP code is creating the json object you listed (and it looks like it would). You can lose the each loop alltogether and set your 2 series like this:
series: [{
name: 'Misure',
color: '#4572A7',
type: 'column',
yAxis: 1,
data: json[1].data,
tooltip: {
valueSuffix: ' Kw'
}
}, {
name: 'Temperature',
color: '#89A54E',
type: 'spline',
data: json[0].data,
tooltip: {
valueSuffix: '°C'
}
}]
http://jsfiddle.net/bhlaird/dUkuY/

How to add MarkerClusterer to my google map

I'm trying to add the Google Cluster to my map, but i cant work out how to do it? i have created the map and its markers with info box using mysql query in php. know i'm adding more markers they are over lapping so i need to add the cluster command but i can't get it working. my code is below
<script>
$(document).ready(function() {
//------- Google Maps ---------//
// Creating a LatLng object containing the coordinate for the center of the map
var latlng = new google.maps.LatLng(53.0,0);
// Creating an object literal containing the properties we want to pass to the map
var options = {
zoom: 5, // This number can be set to define the initial zoom level of the map
center: latlng,
disableDefaultUI: true,
panControl: false,
zoomControl: true,
scaleControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP, // This value can be set to define the map type ROADMAP/SATELLITE/HYBRID/TERRAIN
styles: [
{
"featureType": "landscape.natural",
"stylers": [
{ "visibility": "simplified" },
{ "color": "#07c6ee" }
]
},{
"featureType": "landscape.man_made",
"stylers": [
{ "visibility": "on" },
{ "hue": "#6e00ff" },
{ "gamma": 1.96 },
{ "lightness": 18 },
{ "saturation": -78 },
{ "color": "#46fcb3" }
]
},{
"featureType": "water",
"stylers": [
{ "visibility": "simplified" },
{ "color": "#f9ec55" }
]
},{
},{
"featureType": "road.highway",
"stylers": [
{ "visibility": "on" },
{ "color": "#7b8080" }
]
},{
"featureType": "road.arterial",
"stylers": [
{ "visibility": "on" },
{ "color": "#808080" }
]
},{
"featureType": "road.local",
"stylers": [
{ "color": "#808080" },
{ "visibility": "on" }
]
},{
"featureType": "road",
"elementType": "labels.text.fill",
"stylers": [
{ "color": "#fefffe" },
{ "visibility": "on" }
]
},{
"featureType": "landscape.man_made",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "road.highway",
"elementType": "labels.icon",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "poi",
"stylers": [
{ "visibility": "off" }
]
},{
}
]
};
// Calling the constructor, thereby initializing the map
var map = new google.maps.Map(document.getElementById('map_div'), options);
// Define Marker properties
var image1 = new google.maps.MarkerImage('http://www.foodhawkers.co.uk/images/map-market.png',
// This marker is 129 pixels wide by 42 pixels tall.
new google.maps.Size(40, 40),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 18,42.
new google.maps.Point(40, 40)
);
//
// Add Marker
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(51.4636101,-0.1382557),
map: map,
icon: image1 // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
});
// Add listener for a click on the pin
google.maps.event.addListener(marker1, 'click', function() {
infowindow1.open(map, marker1);
});
// Add information window
var infowindow1 = new google.maps.InfoWindow({
content: createInfo('Venn Street Market', '<div style="width:200px">...</div><br /><br />View profile')
});
var marker2 = new google.maps.Marker({
position: new google.maps.LatLng(51.5367954,-0.0618898),
map: map,
icon: image1 // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
});
// Add listener for a click on the pin
google.maps.event.addListener(marker2, 'click', function() {
infowindow2.open(map, marker2);
});
// Add information window
var infowindow2 = new google.maps.InfoWindow({
content: createInfo('Broadway Market', '<div style="width:200px">...</div><br /><br />View profile')
});
var marker3 = new google.maps.Marker({
position: new google.maps.LatLng(51.4721386,-2.7580983),
map: map,
icon: image1 // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
});
// Add listener for a click on the pin
google.maps.event.addListener(marker3, 'click', function() {
infowindow3.open(map, marker3);
});
// Add information window
var infowindow3 = new google.maps.InfoWindow({
content: createInfo('StrEAT Food Market', '<div style="width:200px">We\'re really hoping to be doing some amazing street food nights in the CENTRE of...</div><br /><br />View profile')
});
var marker4 = new google.maps.Marker({
position: new google.maps.LatLng(51.5945845,-0.1302629),
map: map,
icon: image1 // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
});
// Add listener for a click on the pin
google.maps.event.addListener(marker4, 'click', function() {
infowindow4.open(map, marker4);
});
// Add information window
var infowindow4 = new google.maps.InfoWindow({
content: createInfo('Alexandra Palace Farmers Market', '<div style="width:200px">Sundays 10:00 - 15:00...</div><br /><br />View profile')
});
var marker5 = new google.maps.Marker({
position: new google.maps.LatLng(51.5050824,-0.0900808),
map: map,
icon: image1 // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
});
// Add listener for a click on the pin
google.maps.event.addListener(marker5, 'click', function() {
infowindow5.open(map, marker5);
});
// Add information window
var infowindow5 = new google.maps.InfoWindow({
content: createInfo('Borough Market', '<div style="width:200px">...</div><br /><br />View profile')
});
var marker6 = new google.maps.Marker({
position: new google.maps.LatLng(51.5057757,-0.1168251),
map: map,
icon: image1 // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
});
// Add listener for a click on the pin
google.maps.event.addListener(marker6, 'click', function() {
infowindow6.open(map, marker6);
});
// Add information window
var infowindow6 = new google.maps.InfoWindow({
content: createInfo('The Real Food Market', '<div style="width:200px">...</div><br /><br />View profile')
});
var marker7 = new google.maps.Marker({
position: new google.maps.LatLng(51.5005095,-0.1131232),
map: map,
icon: image1 // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
});
// Add listener for a click on the pin
google.maps.event.addListener(marker7, 'click', function() {
infowindow7.open(map, marker7);
});
// Add information window
var infowindow7 = new google.maps.InfoWindow({
content: createInfo('Lower Marsh Market', '<div style="width:200px">Lower Marsh is steeped in history as one of London’s oldest and best-loved market streets....</div><br /><br />View profile')
});
var marker8 = new google.maps.Marker({
position: new google.maps.LatLng(51.4682204,-0.0259369),
map: map,
icon: image1 // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
});
// Add listener for a click on the pin
google.maps.event.addListener(marker8, 'click', function() {
infowindow8.open(map, marker8);
});
// Add information window
var infowindow8 = new google.maps.InfoWindow({
content: createInfo('Brockley Market', '<div style="width:200px">...</div><br /><br />View profile')
});
var marker9 = new google.maps.Marker({
position: new google.maps.LatLng(51.4528397,-0.1019773),
map: map,
icon: image1 // This path is the custom pin to be shown. Remove this line and the proceeding comma to use default pin
});
// Add listener for a click on the pin
google.maps.event.addListener(marker9, 'click', function() {
infowindow9.open(map, marker9);
});
// Add information window
var infowindow9 = new google.maps.InfoWindow({
content: createInfo('Herne Hill Farmers Market', '<div style="width:200px">...</div><br /><br />View profile')
});
var markerCluster = new MarkerClusterer(options, markers);
// Create information window
function createInfo(title, content) {
return '<div class="infowindow"><strong>'+ title +'</strong><br />'+content+'</div>';
}
});
</script>
Which version of MC you are using? Because version 2.0.x has following construct syntax:
var markerCluster = new MarkerClusterer(map, opt_markers, opt_options);
Try this:
var markerCluster = new MarkerClusterer(map);
markerCluster.addMarker(marker1);
...
markerCluster.addMarker(marker9);
Or, keep Your markers in array, add this to top of Your code:
var markers = [];
After declaring each marker add it to that array:
markers.push(markerN);
And add all of them at once to cluster:
markerCluster.addMarkers(markers);

Categories