Important alert: (current site time 6/19/2013 5:55:41 PM EDT)
 

VB icon

Google map cluster with JSON

Email
Submitted on: 4/27/2012 5:23:06 PM
By: Amit Kumar Gaur  
Level: Advanced
User Rating: Unrated
Compatibility: PHP 5.0
Views: 1568
author picture
(About the author)
 
     Google map cluster with JSON When will cluster not work!. I have identified that , if php script or any other server side script output in json and save it in file; and then use that file into google map cluster , then it will not work. So don't use php or any other server side script which output in json in to system file, instead of json use direct values.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Google map cluster with JSON
// Description:Google map cluster with JSON
When will cluster not work!.
I have identified that , if php script or any other server side script output in json and save it in file; and then use that file into google map cluster , then it will not work.
So don't use php or any other server side script which output in json in to system file, instead of json use direct values.
// By: Amit Kumar Gaur
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=3011&lngWId=8//for details.//**************************************

// Get data from database and store it in $data variable.
// encode it in json
$json = json_encode($data);
// write it into "demo.json" file.
fwrite($fh, $json);
// use that file in map
$('#map_canvas').gmap().bind('init', function() {
$.getJSON( 'http://localhost:90/testmapclustermarker/json/demo.json', function(data) {
 //put here marker cluster code, you can see cluster will not show/work.
} );
});
// == instead of above code use this below code ==
<div id="map_canvas" class="map" style="height:600px;"></div>
<script type="text/javascript">
//first use map api as:
$('#map_canvas').gmap().bind('init', function(evt, map) {
// start here your server side programming tag:
// connect to database and iterate it. don't store it in file system and don't convert it in json format.
// while not end database
// end here your server side programming tag:
var marker_img="http://localhost:90/test/img/test.png";
$('#map_canvas').gmap('addMarker', {
'position': new google.maps.LatLng(<?php echo (float)$row['lat'];?>,<?php echo (float)$row['log'];?>),
'icon':new google.maps.MarkerImage(marker_img,new google.maps.Size(32,37)),
'bounds': true,
animation: google.maps.Animation.DROP,
}).click(function() {// marker.content
$('#map_canvas').gmap('openInfoWindow', { 'content': "test"}, this);
} );
// end loop database.
// set cluster here
var mcOptions = {gridSize: 50, maxZoom: 9, minimumClusterSize: 15, title: 'test'};
$('#map_canvas').gmap('set', 'MarkerClusterer', new MarkerClusterer(map, $(this).gmap('get', 'markers'), mcOptions));
</script>
Get full code here:
http://amitkgaur.blogspot.in/2010/10/google-map-cluster-with-json.html


Other 30 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.