JavaScript在智能手机上的应用-使用手机GPS定位用户所在城市

————————————————————————————

<script type="text/javascript" language="javascript" src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
            //初始化函数
            function init(){
                //判断google的城市是否可用
                if( google.loader.ClientLocation.address.city) {
                    //通过google的api获取城市信息
                    var locationCity = google.loader.ClientLocation.address.city;
                    alert(locationCity);//展示城市的信息结果
                }
            }
</script>

——————————————————————————

<body onload="init();">
    </body>

——————————————————————————

posted @ 2016-10-08 19:40  承载梦想-韩旭明  阅读(2586)  评论(0编辑  收藏  举报