Add markers from json in php page with maps [duplicate]
I'm trying to plot markers in php page with Google Maps api controlled by radio buttons. All data markers are loading correctly (json) but the map does not render. Please see below the code that I'm trying to run. I rebuild all code, the service API returns [{"car":"16","bike":"20","skate":"63","lat":"19.79956153","lon":"42.51250001"},{"car":"23","bike":"21","skate":"65","lat":"19.79980055","lon":"42.51244114"},]
Currently the error on console describes Uncaught ReferenceError: initialize is not defined at HTMLInputElement.onclick.
<html>
<head>
<title>Google Maps</title>
<meta name="author" content=""/>
<meta name="keywords" content="phone"/>
<script src="https://maps.googleapis.com/maps/api/js?key=key"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
var latlng = { lat: 19.7, lng: 42.5 };
var marker;
var map;
var markers=[];
function addmarker(map, lat, lng, title ){
marker = new google.maps.Marker({
position:{ lat:lat,lng:lng },
title:title,
draggable:true,
map:map
});
markers.push( marker );
}
function initialize() {
var mapCanvas = document.getElementById('mapArea');
var mapOptions = {
center: latlng,
zoom: 19,
mapTypeId: google.maps.MapTypeId.SATELLITE
}
function() {
var radio = "";
for (i = 0; i < document.getElementsByName('rd').length; i++) {
if (document.getElementsByName('rd')[i].checked) {
radio = document.getElementsByName('gender')[i].value;
}
}
$.ajax({
dataType: 'JSON',
url: 'http://webservice.net/data.php',
success: function(data) {
markers.forEach( function( e,i,a ){
e.setMap( null );
});
for( var o in data ){
var lat=Number(data[o].lat);
var lng=Number(data[o].lon);
var value=Number(data[o].radio);
console.log( 'lat:%s, lng:%s',lat,lng );
addmarker.call( this, map, lat, lng, val );
}
},
error: function( err ){
console.log( err );
}
})
}
}
google.maps.event.addDomListener(window, 'load', initialize());
</script>
</head>
<body>
<form action="" method="post">
<input type="radio" value="car" name="rd" />Car
<input type="radio" value="clay" name="rd" />Bike
<input type="radio" value="bike" name="rd" />Skate
<input type="button" value="send" onclick="initialize();"/>
</form>
<div id="mapArea" style="width: 1000px; height: 600px;"> </div>
</body>
</html>
from Recent Questions - Stack Overflow https://ift.tt/2Y1dGCM
https://ift.tt/eA8V8J
Comments
Post a Comment