私は過去 8 時間、非常に簡単なことをしようとしてきました。
問題は、私が JavaScript や Google Maps API にあまり詳しくないことです。
私がやりたいのは、2 つの異なる場所の中心を見つけて、それに応じてズームすることだけです。
ユーザーが情報を入力するため、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>