zoukankan      html  css  js  c++  java
  • Google Maps Application Developing —— Location

     
    <script type="text/javascript">
        (function () {
            var map;
            window.onload = function () {
                // Creating a map
                var mapOptions = {
                    zoom: 15,
                    center: new google.maps.LatLng(31.35, 3.51),
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById('map'), mapOptions);
                // Checking if geo positioning is available
                if (geo_position_js.init()) {
                    // Creating a settings object
                    var settings = {
                        enableHighAccuracy: true
                    };
                    // Trying to determine the location of the user
                    geo_position_js.getCurrentPosition(setPosition, handleError, settings);
                } else {
                    alert('目前设备不支持地理定位!');
                }
            };
            function handleError(error) {
                alert('Error = ' + error.message);
            }
            function setPosition(position) {
                // Creating a LatLng from the position info
                var latLng = new google.maps.LatLng(position.coords.latitude,
    position.coords.longitude);
                // Adding a marker to the map
                var marker = new google.maps.Marker({
                    position: latLng,
                    map: map
                });
                // Creating an InfoWindow
                var infoWindow = new google.maps.InfoWindow({
                    content: '你在这里!'
                });
                // Adding the InfoWindow to the map
    
                infoWindow.open(map, marker);
                // Zooming in on the map
                map.setZoom(15);
            }
        })();
    </script>

    作者:Create Chen
    出处:http://technology.cnblogs.com
    说明:文章为作者平时里的思考和练习,可能有不当之处,请博客园的园友们多提宝贵意见。
    知识共享许可协议本作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可。

  • 相关阅读:
    2016Wireshark
    移动UI
    Javascript 严格模式详解
    [转]深入浅出JSONP解决ajax跨域问题
    savedev和save的区别
    jquery各版本区别
    Webpack学习笔记(一)
    Html5新特性
    chrome浏览器debug
    bootstrap笔记
  • 原文地址:https://www.cnblogs.com/technology/p/2331527.html
Copyright © 2011-2022 走看看