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 中国大陆许可协议进行许可。