i have js snippet displays icons on map description. occasionaly map not display , have
"syntax error: missing } after property list"
while debuging in firefox. couldn't find mistake in code figured out might due special signs in variable names like: "," "()", etc. there way make code symbol-proof?
// <![cdata[ jquery(document).ready( function() { jquery("#mapobjects").googlemaps({ "datasource": "recordset", "datasourcetype": "dynamic", "zoom": "fit", "markers": [ <? php { ?> { "latitude": <? php echo $row_recordsetmapa['object_lat']; ?> , "longitude": <? php echo $row_recordsetmapa['object_lng']; ?> , "html": "<a href='obiekt.php?oid=<?php echo $row_recordsetmapa['id_object']; ?>'><?php echo $row_recordsetmapa['object_name']; ?>", "title": "<?php echo $row_recordsetmapa['object_name']; ?>", "icon": { "image": "images//m<?php echo $_get['cat']; ?>.png", "iconsize": [70, 70], "iconanchor": [13, 26], } }, <? php } while ($row_recordsetmapa = mysql_fetch_assoc($recordsetmapa)); ?> ] }); } ); // ]]>
create markers javascript array json_encode creating such data manually not way. check answer on link json.parse() isn't working
also dummy example of question below;
<?php $markerobject = new stdclass(); $markerobject->latitude = "41.015137"; $markerobject->longitude = "28.979530"; $markerobject->html = "<a href=\"href...\">bla bla...</a>"; $markerobject->title = "marker title"; $markerobject->icon = new stdclass(); $markerobject->icon->image = "path_of_image.png"; $markerobject->icon->iconsize = array(); $markerobject->icon->iconsize[] = 70; $markerobject->icon->iconsize[] = 70; $markerobject->icon->iconanchor = array(); $markerobject->icon->iconanchor[] = 13; $markerobject->icon->iconanchor[] = 26; $markers = array(); for($i=0;$i<=4;$i++) { $markers[] = $markerobject; } $markersjson = json_encode($markers); ?>
working example of php code above here https://ideone.com/apxfm9 , javascript code should below;
// <![cdata[ jquery(document).ready( function() { jquery("#mapobjects").googlemaps({ "datasource": "recordset", "datasourcetype": "dynamic", "zoom": "fit", "markers": <?php echo $markersjson; ?> }); } ); // ]]>
Comments
Post a Comment