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);
    }
    }
    });
    }
    };

      

     

  • 相关阅读:
    制作A4纸打印的网页像素大小设置(转)
    关于Vue.use()详解
    Vue的axios如何全局注册
    JS中的apply,call,bind深入理解
    JS异步编程 (2)
    JS异步编程 (1)
    彻底搞清楚javascript中的require、import和export(js模块加载规范的前世今生)
    IPv6地址分类及表示方法
    SublimeText3追踪函数工具CTags设置及使用
    转-编写CGI小结
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2130305.html
Copyright © 2011-2022 走看看