Home  >  Article  >  Web Front-end  >  Small example of Google Maps API displaying a map_html/css_WEB-ITnose

Small example of Google Maps API displaying a map_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:55:40779browse

Source: http://www.ido321.com/1089.html

Effect (tested in new version of Firefox):

Code:

<!DOCTYPE><html><head>    <meta http-equiv="content-type" content="text/html;charset=utf-8">    <title>Google Map</title>    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>    <script type="text/javascript">        function init()        {            // 获取当前位置            navigator.geolocation.getCurrentPosition(function(position)                {                    var coords = position.coords;                    // 设定地图参数,将当前位置的经纬度设置为中心点                    var latlng = new google.maps.LatLng(coords.latitude,coords.longitude);                    var myOptions =                     {                        // 放大倍数                        zoom:14,                          // 标注坐标                        center:latlng,                        // 地图类型                        mapTypeId:google.maps.MapTypeId.ROADMAP                    };                    var map1;                    // 显示地图                    map1 = new google.maps.Map(document.getElementById('map'),myOptions);                    // 创建标记                    var marker = new google.maps.Marker(                        {                            position:latlng,                            map:map1                        });                    // 设定标注窗口,附上注释文字                    var infowindow = new google.maps.InfoWindow(                        {                            content:"当前位置"                        });                    // 打开标注窗口                    infowindow.open(map1,marker);                });        }    </script></head><body onload="init()">    <div id="map" style="width:400px; height:400px"></div></body></html>

Google Maps JavaScript API v3 (reference documentation): https://developers.google.com/maps/documentation/javascript/basics

Baidu Map API reference document: http://developer.baidu.com/map/jsmobile.htm

Next article: How to add Alipay payment function to the website? ? ?


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn