日期:2014-05-16 浏览次数:20500 次
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=MyGoogleAPIkey&sensor=false&language=en"></script>
<script type="text/javascript">
$(window).load(function(){
var geocoder;
var map;
geocoder = new google.maps.Geocoder();
var mapOptions = {
center: new google.maps.LatLng(39.90403, 116.40752599999996),
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
//map_canvas是显示地图的一个DIV
map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions);
//hotelLocal是一个放地址的hidden元素,用来提交到google取得地理编码,也就是坐标。
var address = document.getElementById('hotelLocal').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,
position:results[0].geometry.location
});
}else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
</script>
Uncaught SyntaxError: Unexpected token ILLEGAL maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/14/main.js:1
[17:47:02.730] SyntaxError: illegal character @ http://maps.gstatic.com/intl/en_ALL/mapfiles/api-3/14/14/main.js:1以外,还有个
[17:47:04.184] TypeError: google.maps.Geocoder is not a constructor @ xxxxxxx.html:237