使用google maps javascript API搜索地址
我创建了以下函数以在JS中显示和寻址:使用google maps javascript API搜索地址,javascript,google-maps,geocoding,Javascript,Google Maps,Geocoding,我创建了以下函数以在JS中显示和寻址: function showMapForm(idDiv, divWidth, divHeight, idLat, idLng) { document.getElementById(idDiv).style.width = divWidth+'px'; document.getElementById(idDiv).style.height = divHeight+'px'; if (document.getElementById(idL
function showMapForm(idDiv, divWidth, divHeight, idLat, idLng) {
document.getElementById(idDiv).style.width = divWidth+'px';
document.getElementById(idDiv).style.height = divHeight+'px';
if (document.getElementById(idLat).value=='' && document.getElementById(idLng).value=='') {
//Paris
iniLat = 48.85455;
iniLng = 2.358627;
} else {
iniLat = document.getElementById(idLat).value;
iniLng = document.getElementById(idLng).value;
}
var latlng = new google.maps.LatLng(iniLat, iniLng);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(idDiv), myOptions);
marker = new google.maps.Marker({
position: new google.maps.LatLng(iniLat, iniLng),
map: map
});
google.maps.event.addListener(map, 'click', function(eve) {
marker.setPosition(eve.latLng);
document.getElementById(idLat).value = marker.getPosition().lat();
document.getElementById(idLng).value = marker.getPosition().lng();
});
}
正如您所看到的,它需要div的id、所需的宽度和高度以及隐藏字段的id(我存储纬度和经度),如果这些值不存在,它将使用巴黎的纬度和经度。
我想做的是改进这个函数,这样它就可以接受一个地址为“巴黎圣约瑟夫街45号”的字符串值,并在找到地址时放置一个标记
我的问题是:你知道有没有办法使用谷歌地图API从搜索字符串中获取纬度和经度?(第一次出现就可以了)使用:使用:必须是最短的答案>>必须是最短的答案>>