2015-06-12 39 views
-1

使用位置的地址和郵政編碼可以在谷歌地圖中獲取確切位置嗎?如果沒有,建議我採取其他方法來解決這個問題。我搜查了很多,但我不知道該怎麼做。在谷歌地圖中查找位置地址

在此先感謝......

+0

這個網站可能是你https://developers.google.com/maps/ –

+0

這個幫助是一個例子https://developers.google.com/maps/documentation/javascript/examples/place-search –

回答

2

下面給出的(地址查詢)是代碼。只需添加位置並點擊地理編碼按鈕。

<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 
    <meta charset="utf-8"> 
    <title>Geocoding service</title> 
<style> 
    html, body{ 
    margin: 0px; 
    padding: 0px; 
    } 
    #panel { 
    position: absolute; 
    top: 5px; 
    left: 50%; 
    margin-left: -180px; 
    z-index: 5; 
    background-color: #fff; 
    padding: 5px; 
    border: 1px solid #999; 
    } 
</style> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false"></script> 
<script> 
var geocoder; 
var map; 
function initialize() { 
geocoder = new google.maps.Geocoder(); 
var latlng = new google.maps.LatLng(-34.397, 150.644); 
var mapOptions = { 
zoom: 13, 
center: latlng 
} 
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); 
} 

function codeAddress() { 
document.getElementById("dis").setAttribute('style','visibility:visible;'); 
var address = document.getElementById('address').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); 
} 
}); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 

</script> 
<style type="text/css"> 
.display{visibility:hidden ;width: 700px;height: 400px;position: fixed;top: 0;left: 0;right: 0;bottom: 0;margin: auto;} 
</style> 
</head> 
<body> 
<div id="panel"> 
    <input id="address" type="textbox" value="Pathankot"> 
    <input type="button" value="Geocode" onclick="codeAddress()"> 
</div> 
<div class="display" id="dis"> 
<div id="map-canvas" style="width:400px;height:400px"></div> 
</div> 
</body> 
</html>