google 根據地址得ip 並顯示

來源:互聯網
上載者:User

參考地址:http://code.google.com/intl/zh-CN/apis/maps/documentation/javascript/examples/index.html

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function codeAddress() {
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);
}
});
}
</script>
</head>
<body onload="initialize()">
<div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Geocode" onclick="codeAddress()">
</div>
<div id="map_canvas" style="height:90%;top:30px"></div>
</body>
</html>

 

自己:

   var g_weidu_min = 31.1235;
var g_weidu_max = 31.28;
var g_jingdu_min = 121.36;
var g_jingdu_max = 121.58; 

 
this.geocode = function(address)
{
alert("123");
if (geocoder) {
var southwest = new google.maps.LatLng(31.1235, 121.36);
var northeast = new google.maps.LatLng(31.28, 121.58);
var bounds = new google.maps.LatLngBounds(southwest, northeast); //限定查詢範圍
geocoder.geocode( { 'address': address, 'bounds': bounds}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
if(results[0].geometry.location.lat() > g_weidu_min && results[0].geometry.location.lat() < g_weidu_max && results[0].geometry.location.lng() > g_jingdu_min && results[0].geometry.location.lng() < g_jingdu_max)
{
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map, //定義在map中顯示標記。
position: results[0].geometry.location //定義標記的位置
});
markersArray.push(marker);
}
}
});
}
};

  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.