开发者

google.maps.Geocoder - can't write data from function to the page

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript">
    var geocoder;
    var loc;
    geocoder = new google.maps.Geocoder();
    var input = "32.83036,34.974339"
    var latlngStr = input.split(",",2);
    var lat = parseFloat(latlngStr[0]);
    var lng = parseFloat(latlngStr[1]);
    var latlng = new google.maps.LatLng(lat, lng);

    geocoder.geocode({'latLng': latlng}, function(results, status) {
        document.write(results[1].formatted_address);
    });


</script>

It doesn't do anythin开发者_如何学编程g. If I'll replace the "document.write" with "alert" it will work. What am I doing wrong?


document.write is evil; if you're using an XHTML DTD it doesn't even work. For more reasons on why not to use document.write: Why is document.write considered a "bad practice"?


Couldn't you just use something like;

document.getElementById('ObjectName').innerText = results[1].formatted_address;

Also results[0].formatted_address (zero not one) will give you a more detailed street name.

Jim

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜