These are the two functions being called, one from HTML code and one from PHP code.The function addMarker
is used to add a Marker at the place which is retrieved from the database. The function codeAddress
is used to place a marker at a location which is entered by the user in HTML form.
The codeAdress
is working fine but `addMarker' is not.
I have also tried executing alert message in the addMarker function and its working fine. However the geocoder function is not working inside it.
I am also writing the function calls for both the functions below the actual code.
function addMarker(address1)
{
geocoder.geocode( {'address': address1}, function(results, status) {
alert(address1);
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
draggable: true,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
draggable: true,
position: results[0].geometry.location
});
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
The html code
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Geocode" onclick="codeAddress()">
The PHP code
echo "<script type='text/javascript'>";
echo "addMarker('$row[address]')";
echo "</script>";