【发布时间】:2012-08-16 03:13:34
【问题描述】:
在过去的 8 个小时里,我一直在尝试做一些极其简单的事情。
问题是我对 JavaScript 和 Google Maps API 都不是很熟悉。
我要做的就是找到 2 个不同位置的中心并相应地缩放。
这两个地址是动态的,因为用户将输入信息。
我的所有搜索都以 API v2 或固定位置结束。
有人可以帮帮我吗?
我真的很感激!
提前非常感谢!!!
<script src="https://maps.googleapis.com/maps/api/js?sensor=false®ion=BR"></script>
<script>
var geocoder;
var map;
var query = "<?php echo $endCercompleto; ?>";
var query2 = "<?php echo $endFescompleto; ?>";
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom:8,
center: new google.maps.LatLng(0, 0),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
codeAddress();
}
function codeAddress() {
var address = query;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
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 address2 = query2;
geocoder.geocode( { 'address': address2}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker2 = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
</script>
【问题讨论】:
-
我需要 V3 并且该链接适用于固定位置/位置。我需要动态
-
我对@987654323@ 的回答应该适用于这种情况。
标签: javascript api google-maps google-maps-api-3 centering