使用定位获取当前位置生成地图,geolocation和sogou map结合使用的代码

学渣笔记·干货
2019-07-27 08:43:27

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>

<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="format-detection" content="telephone=no,email=no,adress=no" />

<title>无标题文档</title>

<style>#map_canvas{width:300px; height:300px; margin:20px;}</style>

<script type="text/javascript" src="//api.map.sogou.com/maps/js/api_v2.5.1.js"></script>

</head>

<script>

window.onload = function() {

    if(navigator.geolocation){

        navigator.geolocation.getCurrentPosition(function(position){

            var myLatlng = new sogou.maps.LatLng(position.coords.latitude,position.coords.longitude);

            var myOptions = {

                zoom: 15,

                center: myLatlng,

                mapTypeId: sogou.maps.MapTypeId.ROADMAP

            }

            var map = new sogou.maps.Map(document.getElementById("map_canvas"), myOptions);

            var marker = new sogou.maps.Marker({

                position: myLatlng,

                map: map,

                title:"我在这里!"

            });

        },

        function(error){

            var errorTypes = {

                1:'位置服务被拒绝,请打开获取位置的权限',

                2:'获取不到位置信息,请打开设备定位服务',

                3:'获取信息超时'

            };

            document.getElementById("geo_loc").innerHTML = errorTypes[error.code];

        });

    }else{

        document.getElementById("geo_loc").innerHTML = "您当前使用的浏览器不支持HTML5 Geolocation服务";

    }

}

</script>

<body>

<div align="center">

<div id="map_canvas"></div>

<div id="geo_loc"></div>

</div>

</body>

</html>

↓  往下拉,下面的文章更精彩  ↓
 1  阿里云ip段大全(整理版)

60.205.0.0-60.205.255.255 59.110.0.0-59...

 2  cookie无效。值不是令牌或引用值。Invalid cookie.Value not a token or quoted value

今天忽然发现tomcat日志里多了这么一段: INFO: Cookies: I...

 3  linux下如何修改巨大数量文件权限,不改文件夹权限

由于以前规划不科学,导致某些目录下存放了巨量文件,有几百万个小文件,操作起来比较...

 4  sphinx配置文件详细说明

To manage indexes: editor /etc/sphinx/...

 5  咖啡能用来醒酒吗?

不少人相信咖啡能帮助醒酒,当看到有谁喝醉时,他们总是建议醉酒者喝一两杯咖啡,说这...

 6  新鲜的肉味道最好吗?

大多数人都以为,刚宰杀的动物肉特别新鲜,因此也是最香味道最好的。其实,最新的研究...

 7  农历就是阴历吗?

我们所过的春节是农历正月初一,通常也说阴历新年。但严格的来说,中国的农历并不是一...

 8  酒精能杀菌消毒吗,纯酒精呢?

酒精能够杀菌消毒,这一点恐怕是人人皆知的常识。 不是么?打针前,漂亮的女护士总...

 9  win10升级后字体变模糊看不清楚了

今天把win10升级到最新版本后,发现字体变得模糊了,变瘦了,好像还断断续续的,...

 10  win10升级遇到的一些问题,升级后版本怎么查看?

昨天早上,操作系统提示更新下载失败,我点进去一看,原来是win10出了新版本,需...

 
回到王朝网络首页