<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="WebApplication4.index" %>

<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="baidu-site-verification" content="zyu2elKF1h">
    <meta name="robots" content="noodp">
    <title>定位</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <%--先申请key值--%>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=9ac9840832477736878e71d403cbe6d55"></script>    
    <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
    <style type="text/css">
        /*删除高德地图的logo*/
          .amap-logo {
            right: 0 !important;
            left: auto !important;
            display: none;
        }
        
        .amap-copyright {
            right: 70px !important;
            left: auto !important;
        }  
    </style>
    </head>
    
<body>
<div id='container'></div>
<div id="tip"></div>
<script type="text/javascript">
    var map, geolocation;
    //加载地图,调用浏览器定位服务
    map = new AMap.Map('container', {
        resizeEnable: true
    });
    map.plugin('AMap.Geolocation', function () {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位,默认:true
            timeout: 10000,          //超过10秒后停止定位,默认:无穷大
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
            zoomToAccuracy: false,      //定位区域
            buttonPosition: 'RB'
        });
        map.addControl(geolocation);
        geolocation.getCurrentPosition();
        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
        AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
    });
    //解析定位结果
    function onComplete(data) {
        var str = ['定位成功'];
        str.push('经度:' + data.position.getLng());       
        str.push('纬度:' + data.position.getLat());
        str.push('精度:' + data.accuracy + ' 米');
        str.push('是否经过偏移:' + (data.isConverted ? '是' : '否'));        
        document.getElementById('tip').innerHTML = str.join('<br>');
    }
    //解析定位错误信息
    function onError(data) {
        document.getElementById('tip').innerHTML = '定位失败';
    }
</script>
</body>
</html>

 

 

 

 

 

 

 

相关资料的查看地址:

各种demo的在线编辑查看地址http://lbs.amap.com/api/javascript-api/example/location/browser-location/?demo

高德自己做的: 打开即有相应的定位信息http://ditu.amap.com/

 

需要自己申请key值,应用等,登陆账号(同百度地图)