试图通过google api v3获取地址的位置 [英] trying to get location from address using google api v3
问题描述
我在html中有这个javascript,我想在这里做的是获得给定位置的地图表示形式。
< ; script type =text / javascript>
var geocoder;
var map;
函数getmaploc(){
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom:8,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
geocoder.geocode('cairo',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不成功:+ status);
}
map = new google.maps.Map(document.getElementById( map_canvas),myOptions);
});
}
< / script>
< body onload =getmaploc()>
< div id =map_canvasstyle =width:320px; height:480px;>< / div>
< / body>
我无法弄清楚这有什么问题吗?
有多个错误, 固定代码: I have this javascript in my html what i want to do here is to get a map representation given the location I cant figure out whats wrong with this any help?? There are multiple errors, fixed code:
这篇关于试图通过google api v3获取地址的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
var geocoder;
var map;
函数getmaploc(){
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom:8,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(map_canvas),myOptions);
geocoder.geocode({
地址:'cairo'
},函数(结果,状态){
console.log(结果);
if(status == google.maps.GeocoderStatus.OK){
map.setCenter(results [0] .geometry.location);
new google.maps.Marker({
map:地图,
位置:results [0] .geometry.location
});
} else {
alert(地理编码失败,原因如下:+ status) ;
}
});
}
<script type="text/javascript">
var geocoder;
var map;
function getmaploc() {
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
geocoder.geocode( 'cairo', 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);
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
});
}
</script>
<body onload="getmaploc()">
<div id="map_canvas" style="width: 320px; height: 480px;"></div>
</body>
var geocoder;
var map;
function getmaploc() {
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom : 8,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder.geocode({
address : 'cairo'
}, function(results, status) {
console.log(results);
if(status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
new google.maps.Marker({
map : map,
position : results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}