用js获取当前地理位置的经纬度

news/2024/7/5 2:38:52
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>H5定位</title>
<style>
*{
padding: 0;
margin: 0;
list-style: none;
}
h1{
text-align: center;
margin: 20px auto;
color: darkgoldenrod;
font-weight: bold;
}
button{
display: block;
width: 50%;
height: 40px;
line-height: 40px;
font-weight: bold;
text-align: center;
border: none;
margin: 30px auto;
border-radius: 3px;
color: #fff;
font-size: 14px;
box-shadow: 4px 4px 5px rgba(0,0,0,0.5);
}
.bt1{
background: green;
}
.bt2{
background:#DB7093;
}
span{
display: block;
text-align: center;
color: deeppink;
}
a{
display: block;
line-height: 24px;
text-align: center;
margin: 10px auto;
}
.footer{
position: absolute;
left: 0;
bottom: 20px;
width: 100%;
color: #474747;
font-size: 12px;
text-align: center;
}
</style>
</head>
<body>
<h1>H5定位</h1>
<p id="pId"></p>
<button class="bt1" οnclick="getLocation()"> 我的经纬度 </button>
<span>点下试试吧!可以获得你的经纬度。</span>
</body>
<script>
var x=document.querySelector("#pId")
function getLocation(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}else{
x.innerHTML="定位失败";
}
}
function showPosition(position){
x.innerHTML="我当前经度为"+position.coords.latitude+",纬度为"+position.coords.longitude+"的地方哦"
}
</script>
</html>

转载于:https://www.cnblogs.com/zhuyupingit/p/6322211.html


http://www.niftyadmin.cn/n/4084358.html

相关文章

python pandas数据清洗_利用Python Pandas进行数据预处理-数据清洗.md

# [利用Python Pandas进行数据预处理-数据清洗](http://blog.csdn.net/yen_csdn/article/details/53445616)标签&#xff1a; [python](http://www.csdn.net/tag/python)[数据分析](http://www.csdn.net/tag/%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90)[异常](http://www.csdn.net/…

iOS8开发~UI布局(三)深入理解autolayout

一、概要 通过对iOS8界面布局的学习和总结&#xff0c;发现autolayout才是主角&#xff0c;autolayout是iOS6引入的新特性&#xff0c;当时还粗浅的学习了下&#xff0c;可是没有真正应用到项目中。随着iOS设备尺寸逐渐碎片化&#xff0c;纯粹的hard code方式UI布局将会走向死角…

java 8安卓_Android中启用Java 8

支持 Java 8 语言功能需要一个名为 Jack 的新编译。Jack 仅在 Android Studio 2.1 和更高版本上才受支持。因此&#xff0c;如果要使用 Java 8 语言功能&#xff0c;则需使用 Android Studio 2.1 开发应用。Java8功能targetSdkVersion>23以下功能特性默认和静态接口方法Lamb…

js判断是否为数组的函数: isArray()

2019独角兽企业重金招聘Python工程师标准>>> 今天刚好在学习支付宝 JS 框架 base.js 。瞄了一下&#xff0c;实现是这样的&#xff1a; if (value instanceof Array ||(!(value instanceof Object) &&(Object.prototype.toString.call((value)) [object Ar…

java 输出excel_java 导出excel方法

到http://download.csdn.net/source/1781433下载jxl.jar文件/*Title是保存出来的文件名&#xff0c;gbl_LastOpenPath用于记录上次打开的路径*/public void ExportToExcel(JTable table, String Title){File DefaultFile;JFileChooser fc new JFileChooser();File file;if(gbl…

shell expect

ubuntu su root****************************************************expect << EOFspawn su rootexpect "密码&#xff1a;" send "$pass\r" expect eofEOF*******************************************************转载于:https://blog.51cto.com…

【ZT】SQL SERVER性能瓶頸監測

当您怀疑计算机硬件是影响SQL Server运行性能的主要原因时&#xff0c;可以通过SQL Server Performance Monitor监视相应硬件的负载&#xff0c;以证实您的猜测并找出系统瓶颈。下文将介绍一些常用的分析对象及其参数。 Memory: Page Faults / sec 如果该值偶尔走高&#xff0c…

java char int 运算符_Java - char, int conversions

小编典典第一个示例(编译)很特殊&#xff0c;因为加法的两个操作数都是文字。以下是一些定义&#xff1a;一个转换int到char被称为基本收缩转换&#xff0c;因为char是比较小的类型int。A 1是一个常量表达式。常量表达式(基本上)是一个表达式&#xff0c;其结果始终相同&#…