views:

27

answers:

0

I have the following code to geocode the entered address but it displays error saying that variables is undefined ,permission is denied can anyone help to tackle this problem .

<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
<script type="text/javascript" >
   var x=codeAddress();

   function codeAddress() {
        var address = ($("#addressLocation").val());
        geocoder.geocode({ 'address': address }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
            var lat1 = results[0].geometry.location.lat();
            var lng1 = results[0].geometry.location.lng();
                alert(lat1);
                alert(lng1);
                var marker = new google.maps.Marker({
                    map: map,
                    position: results[0].geometry.location
                });
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
        var lat;
        var lng;
        var r = {};
        r.lat = lat1;
        r.lng = lng1;

        return r;

    }