- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果用户不共享 google map
的位置。向他显示提醒,要求他在所有设备上共享您的位置
。这是我的代码
if(navigator.geolocation) {
var latitude="";
navigator.geolocation.getCurrentPosition(function(position) {
var latitude =position.coords.latitude;
var longitude= position.coords.longitude;
$('lati-longi').setValue(latitude+','+longitude);
var map;
var res=getmapbygolocation(latitude,longitude);
})}else { alert("dsfds"); //this alert is not working
}
警报消息不起作用,因为 if 始终为 true。
最佳答案
通过使用 if(navigator.geolocation){},您可以检查浏览器是否支持地理位置。
如果您尝试检查用户是否未共享位置,可以使用 getCurrentPosition 函数的错误回调。更多信息与示例,您可以找到 here
上面链接中的一个工作示例是 here
HTML:
<div>
<button id="btnInit" >Find my location</button>
</div>
Javascript:
jQuery(window).ready(function(){
jQuery("#btnInit").click(initiate_geolocation);
});
function initiate_geolocation() {
navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);
}
function handle_errors(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED: alert("user did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE: alert("could not detect current position");
break;
case error.TIMEOUT: alert("retrieving position timed out");
break;
default: alert("unknown error");
break;
}
}
function handle_geolocation_query(position){
alert('Lat: ' + position.coords.latitude +
' Lon: ' + position.coords.longitude);
}
关于javascript - 显示提醒消息以分享您的位置谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32885998/
直接上代码,可以写在公共文件common和继承的基础类中,方便调用 ?
1、php服务端环境搭建 1.php 服务端环境 安装套件 xampp(apach+mysql+php解释器) f:\mydoc文件(重要)\dl_学习\download重要资源\apache
如下所示: Eclipse快捷键 Ctrl+1 快速修复 Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加) Ctrl+Alt+↑ 复制当前行到上一行(复制增加)
第一步:conn.PHP文件,用于连接数据库并定义接口格式,代码如下: php" id="highlighter_808731">
本篇文章整理了几道Linux下C语言的经典面试题,相信对大家更好的理解Linux下的C语言会有很大的帮助,欢迎大家探讨指正。 1、如果在Linux下使用GCC编译器执行下列程序,输出结果是什么?
安装完最新的Boost库 官方说明中有一句话: Finally, $ ./b2 install will leave Boost binaries in the lib/ subdirecto
为了梳理前面学习的《spring整合mybatis(maven+mysql)一》与《spring整合mybatis(maven+mysql)二》中的内容,准备做一个完整的示例完成一个简单的图书管理功
网站内容质量仅仅是页面综合得分里面的一项.不管算法如何改变调整,搜索引擎都不会丢弃网站页面的综合得分。 一般情况下我们把页面的综合得分为8个点: 1、标题的设置 (标题的设置要有独特性)
最近事情很忙,一个新项目赶着出来,但是很多功能都要重新做,一直在编写代码、debug。今天因为一个新程序要使用fragment来做,虽然以前也使用过fragment,不过没有仔细研究,今天顺道写篇文
Android资源命名规范 最近几个月,大量涉及android资源的相关工作。对于复杂的应用而言,资源命名的规范很有必要。除了开发人员之外,UI设计人员(或者切图相关人员)也需要对资源使用的位置非常
以前一直使用Hibernate,基本上没用过Mybatis,工作中需要做映射关系,简单的了解下Mybatis的映射。 两者相差不多都支持一对一,一对多,多对多,本章简单介绍一对一的使用以及注意点。
如下所示: ? 1
如果想在自定义的View上面显示Button 等View组件需要完成如下任务 1.在自定义View的类中覆盖父类的构造(注意是2个参数的) 复制代码 代码如下: publ
实现功能:实现表格tr拖动,并保存因为拖动改变的等级. jsp代码 ?
代码:测试类 java" id="highlighter_819000"> ?
红黑树是一种二叉平衡查找树,每个结点上有一个存储位来表示结点的颜色,可以是red或black。 红黑树具有以下性质: (1) 每个结点是红色或是黑色 (2) 根结点是黑色的 (3) 如果一个
废话不多说,直接上代码 ? 1
码代码时,有时候需要根据比较大小分别赋值: ? 1
实际项目开发中,我们经常会用一些版本控制器来托管自己的代码,今天就来总结下Git的相关用法,废话不多说,直接开写。 目的:通过Git管理github托管项目代码 1、下载安装Git 1、下载
直接上代码: 复制代码 代码如下: //验证码类 class ValidateCode { private $charset = 'abcdefghkmnprstuvwxyzABC
我是一名优秀的程序员,十分优秀!