开发者

Google Geocoder Problems

开发者 https://www.devze.com 2023-02-22 18:29 出处:网络
I am trying to geocode an address given by the user in the text field, however my JavaScript function does not execute from the line \"geocoder.geocode ({\'address\':address......\" onwards.

I am trying to geocode an address given by the user in the text field, however my JavaScript function does not execute from the line "geocoder.geocode ({'address':address......" onwards.

I am stuck here not sure why it doesn't work. It throws thee first alert box showing the address field pulled over to the client script but does not work after that. It just stays without any action. Please let me know where i need to correct. Here is the client side code.

var map;
var geocoder;
function initialize()
{
    geocoder = new google.maps.Geocoder();  
}
function getgeocode() {  
    var address = document.advpollsrch.txtaddress.value;
    alert(address);
    geocoder.geocode( {'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            alert("Geocode was successful");
            var latlng = results[0].geometry.location;
            document.advpollsrch.hidlatitude.value = latlng.lat();
            document.advpollsrch.hidlongitude.value = latlng.lng();
            alert("Geocode split was successful");
            return true;
        } else {
            alert("Geocode was not successful for the following reason: " + status);
            return false;
        }
    });
}  
<body onload="initialize()">
    <form  name="advpollsrch"> <!-- onsubmit="return getgeocode()" -->
        <input type="hidden" name="hidlatitude" id="hidlatitude"></input>
        <input type="hidden" name="hidlongitude" id="hidlongitude"></input>

        <p style="font-weight:bold; float:left; margin-left:0px;">STEP 1 - </p>
        <div style="border: 1px dotted #000000;width: auto; height: auto; padding: 0px 8px 0px 8px; margin:0px 8px 0px 12px; float:left;">
            <table border="0" cellpadding="0" cellspacing="10">
                <tr>
                    <td>
                        <label for="staddress">Street Address</label><br />
                        <input type="text" width="300" name="txtaddress" id="txtaddress" value=""></input>
                    </td>
                    <td>
                        <label for="city">City</label><br />
                        <input type="text" width="150" name="txtcity" id="txtcity" value=""></input>
                    </td>
                </tr>
            </table>
        </div>
        <h3 style="padding: 0px 8px 0px 8px;float:left;">Or</h3>
        <div style="border: 1px dotted #000000; width: auto; height: auto;padding: 5px 8px 5px 8px; margin: 0px 8px 0px 12px; float:left;">
            <table border="0" cellspacing="5" cellpadding="0">
                <tr>
                    <td>
                        <label for="staddress">Town / RM/ Village / First Nation</label><br />
                        <input type="text" width="300" name="txtplace" id="txtplace" value=""></input>
                    </td>
                </tr>
            </table>    
        </div>
        <br /><br /><br /><br />
        <p style="font-weight:bold; float:left; margin-left:0px;">STEP 2 - </p> 
        <div style="border: 1px do开发者_开发知识库tted #000000; width: auto; height: auto;padding: 0px 8px 2px 8px; margin: 0px 8px 0px 12px; float:left;"> 
            <table border="0" cellspacing="5" cellpadding="0">
                <tr>
                    <td>    
                        <label for="radius">Select the distance</label><br />
                        <select id="radius" name="radius">
                            <option value="0">Choose Distance:</option>
                            <option value="2">2 kilometers</option>
                            <option value="4">4 kilometers</option>
                            <option value="6">6 kilometers</option>
                            <option value="8">8 kilometers</option>
                        </select>
                    </td>
                </tr>
            </table>
        </div>  
        <br /><br /><br />
        <p style="font-weight:bold; float:left;">STEP 3 - </p>
        <div style="padding: 15px 8px 2px 0px; margin: 0px 8px 0px 12px; float:left;">
            <input type="button" value="Find Advance Poll locations" onclick="getgeocode()"></input>    
        </div>
    </form>  <br />

    <div style="margin-top:50px; margin-left:-3px;">
        <iframe id="gmaps" name="gmaps" src="showpoints_jq.html" frameborder="no" scrolling="no" width="780px" height="520px"></iframe>
    </div>
</body>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号