zoukankan      html  css  js  c++  java
  • google 根据地址得ip 并显示

    参考地址: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);
    }
    }
    });
    }
    };

      

     

  • 相关阅读:
    2021,6,10 xjzx 模拟考试
    平衡树(二)——Treap
    AtCoder Beginner Contest 204 A-E简要题解
    POJ 2311 Cutting Game 题解
    Codeforces 990G GCD Counting 题解
    NOI2021 SDPTT D2T1 我已经完全理解了 DFS 序线段树 题解
    第三届山东省青少年创意编程与智能设计大赛总结
    Luogu P6042 「ACOI2020」学园祭 题解
    联合省选2021 游记
    Codeforces 1498E Two Houses 题解 —— 如何用结论吊打标算
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2130305.html
Copyright © 2011-2022 走看看