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>
posted @ 2012-01-30 00:37  Create Chen  阅读(1118)  评论(2编辑  收藏  举报