I found many syntax errors:
- After the split, there's no
;. - For some reason you closed the function with
}); when only } is needed. - The
marker variable closes right after title:"" with }); so the curly bracket after it shouldn't be there.
Other than that, I don't see why it's not working. Please show where you're calling initialize();
For now, use this code instead:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=>123456&sensor=false"></script> <script type="text/javascript"> function initialize(lat, lng){ // edited on first edit alert("before"); var LatLng = { // edited on first edit lat: lat, lng: lng }; alert("after"); var mapOptions = { center: latlng, zoom: 17, mapTypeId: google.maps.MapTypeId.HYBRID }; var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); var marker = new google.maps.Marker({ position: latlng, map: map, title: "" }); } </script>
- EDIT -
Alright, so you call the function with this:
<img onload="javascript:initialize('<?php echo $row_record['pzcoordi'];?>');" src="images/blank.gif"/>
First, I would use a div instead of an img, but if it works, that's ok. I see your approach to pass a parameter and then split it on JavaScript. Pretty genius. But I see you are passing the parameter as a string. This won't work because the API expects them to be integer.
To diagnose better, I would love to see how you built those next and previous buttons, since they work fine, but I will just move on with my guess.
I suggest that you pass 2 parameters, the Lat and Lng coordinates, and to achieve that, you need to explode(); them in PHP:
<?php $array = explode(",", $row_record['pzcoordi']); $lat = $array[0]; $lng = $array[1]; ?> <img onload="initialize(<?php echo $lat; ?>, <?php echo $lng; ?>)" src="images/blank.gif"/>
If this doesn't work for any reason, maybe you could wrap the parameters with single quotes to make them strings, but I wouldn't rely on that. And I know that explode(); returns strings, but they will only be strings for HTML and PHP, JavaScript will take them as integers because they won't be wrapped with single quotes. I hope this helps.
initializefunction?