android:应用程序内定位处理,百度定位,高德定位,系统定位处理.

文章来自:http://blog.csdn.net/intbird

    • 关于定位的几点体验
    • 地图上使用定位
    • 定位信息说明
    • 应用内确保定位返回结果思考
    • 应用内使用定位服务代码
    • 代码基础使用方法

关于定位的几点体验:

  • 百度定位:定位返回很快,很及时,推荐使用,单次定位,能很大程度的保证应用获取位置,5.1的定位有了位置提醒;
  • 高德定位:和系统的很像,需要设置定位的米和时间,有时候不返回,有时候返回一大推,不清楚它机制是什么,不推荐;
  • 系统定位:单纯的户外使用返回还是很不错的,如果是做一个骑行记录轨迹的,系统的不会产生重复记录,即看你的参数设置,不动可不返回结果;

地图上使用定位:

地图上没有自带的定位方式,即地图和定位是独立的,可以让任意的位置信息放入 我的位置 上,也可以用高德地图,用百度定位,让使用中的地图去显示小蓝点,当然也可以是自己定位的任意样式;

定位信息说明:

-百度定位:定位类型可以默认就很好;

在startLocation()时貌似会返回两次定位结果,request好像是返回一次结果,百度定位的时间联网时时网络时间,时间格式是字符串,在网络定位时会返回具体信息,如果是断网情况下,返回当前手机时间,不定位不耗电,定位经纬度位数比较短;

-高德地图:定位类型有三种,AmapNetWork即可,request(),应该和系统定位是一致的,返回时间为当前手机时间,如果没有订到位置,getLastKnow为上一次定位时间,lbs包含更多信息,定位经纬度位数比较长;

-系统定位:定位类型有三种,network,gps,passive,在室内使用返回成功几乎不可能,在网络定位还好,

应用内确保定位返回结果思考

如果定位结果包含反地理编码信息,则直接保存结果,如果是gps定位信息,则进行反地理编码,保存结果

如果长时间取不到位置,则由定时器返回上次位置

如需要处理位置的重复返回多次,根据HashMap的类型去获取上次该类型的具体信息,主要为判断该类型的时间间隔,精度纬度偏差等等,如果偏差较小,可拦截该次定位结果

应用内使用定位服务代码:

BDLocationManager.java

GDLocationManager.java

MyAppLocation.java;

MyAppLocationListener.java;

  1. BDLocationManager.java
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

/**
 * 百度定位5.1
 * @author intbird
 *
 */
public class BDLocationManager {

    private static BDLocationManager instance = null;
    private static final int timeOutLocation = 8*1000;
    private static final int timeSpanLocation= 500;//单次定位

    public LocationClient mLocationClient;
    private MyBDLocationListener mBDLocationListener;

    private MyAppLocationListener myAppListener;

    public static BDLocationManager getInstance(){
        if (instance == null){
           instance = new BDLocationManager();
        }
        return instance;
    }

    private BDLocationManager(){
        super();
        //定位初始化
        mLocationClient = new LocationClient(AppContext.getInstance().getApplicationContext());
        mBDLocationListener = new MyBDLocationListener();
        mLocationClient.registerLocationListener(mBDLocationListener);
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true);//打开gps
        option.setAddrType("all");
        option.setCoorType("bd09ll"); //设置坐标类型
        option.setScanSpan(timeSpanLocation);
        option.setTimeOut(timeOutLocation);
        mLocationClient.setLocOption(option);
    }

    public void start(MyAppLocationListener listener){
        this.myAppListener = listener;
        if (mLocationClient != null){
            if(mLocationClient.isStarted()){
                mLocationClient.requestLocation();
            }else{
                mLocationClient.start();
            }
        }
    }

    public void destroy(){
        //mLocationClient.stop();
        //mLocationClient.unRegisterLocationListener(mBDLocationListener);
    }

    private class MyBDLocationListener implements BDLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location) {
            if(location==null) return;
            int locType = location.getLocType();
            if(locType==BDLocation.TypeGpsLocation ||
                        locType==BDLocation.TypeNetWorkLocation||
                        locType==BDLocation.TypeOffLineLocation||
                        locType==BDLocation.TypeCacheLocation ){
            MyAppLocation.getInstance().onLocationSussess(location, myAppListener);
            destroy();
          }else{
              MyAppLocation.getInstance().onLocationedFaild(myAppListener);
              if(locType==BDLocation.TypeServerError){
                  MyToast.showToast(Frame.getInstance().getAppContext(),"定位失败,请允许使用位置服务");
              }
          }
        }
    };

    public BDLocation getLastKnowLocation(){
        if(mLocationClient!=null){
            return  mLocationClient.getLastKnownLocation();
        }
        return null;
    }
}
  1. GDLocationManager.java
import android.location.Location;
import android.os.Bundle;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.amap.api.location.LocationProviderProxy;

/**
 * 高德定位,NOTE:有时可能不返回定位结果;
 * @author intbird
 *
 */
public class GDLocationManager {
    private static GDLocationManager instance = null;
    private int locTimemills = 2 * 60 * 1000;
    private int locMeters  = 300;

    private LocationManagerProxy aMapManager;
    private MyAMapLocationListener aMapLocationListener;
    private MyAppLocationListener myAppListener;

    public static GDLocationManager getInstance(){
        if (instance == null){
           instance = new GDLocationManager();
        }
        return instance;
    }

    private GDLocationManager(){
        super();
        aMapManager = LocationManagerProxy.getInstance(AppContext.getInstance().getApplicationContext());
        aMapLocationListener = new MyAMapLocationListener();
    }

    public void start(MyAppLocationListener listener) {
        this.myAppListener = listener;
        if (aMapManager == null) {
            aMapManager.requestLocationData(LocationProviderProxy.AMapNetwork, locTimemills, locMeters, aMapLocationListener);
        }
    }

    public void destroy() {
        if (aMapManager != null) {
            aMapManager.removeUpdates(instance.aMapLocationListener);
            aMapManager.destroy();
        }
    }

    public AMapLocation getLastKnowLocation(){
        if(aMapManager!=null){
            return aMapManager.getLastKnownLocation(LocationProviderProxy.AMapNetwork);
        }
        return null;
    }

    private class MyAMapLocationListener implements AMapLocationListener{

        @Override
        public void onLocationChanged(Location location) {

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {

        }

        @Override
        public void onProviderEnabled(String provider) {

        }

        @Override
        public void onProviderDisabled(String provider) {

        }

        @Override
        public void onLocationChanged(AMapLocation amapLocation) {
            if(amapLocation != null){
                if(amapLocation.getAMapException().getErrorCode() == 0) {
                    MyAppLocation.getInstance().onLocationSussess(amapLocation, myAppListener);
                    destroy();
                }else {
                    MyAppLocation.getInstance().onLocationedFaild(myAppListener);
                }
            }
        }
    }
}
  1. MyAppLocation.java;

    java

    HashMap<MapType, HashMap<String, String>> mapGpsContains

    = new HashMap<MapType, HashMap<String,String>>();//用于位置去重;


import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.os.CountDownTimer;
import android.text.TextUtils;
import com.amap.api.location.AMapLocation;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.RegeocodeAddress;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.baidu.location.BDLocation;
import com.idonoo.frame.GlobalInfo;
import com.idonoo.frame.dao.DbGPSInfo;
import com.idonoo.frame.types.MapType;

/**
 * 负责app内定位信息
 * @author intbird
 *
 */
public class MyAppLocation {

    private static MyAppLocation bdLocation;
    public static MyAppLocation getInstance() {
        if(bdLocation==null){
            bdLocation = new MyAppLocation();
        }
        return bdLocation;
    }

    private MyAppLocationListener locationListener;
    private CountDownTimer timer;
    private int timeOutCacelLocation = 8*1000;

    public MyAppLocation(){
        GlobalInfo.getInstance().setGpsInfo(LocationInfoUtil.getGpsInfo());//看哪个先调用;
        getTimerLocation();
    }

    /**
     * 仅用于保存位置使用.尽量使用true,已防止经纬度和地址不匹配;
     * @param isSilentRegeo 是否静默使用定位且反地理编码
     */
    public void startLocation(boolean isSilentRegeo){
        if(isSilentRegeo){
            MyDefaultAppLocationInfoListener listener= new MyDefaultAppLocationInfoListener();
            listener.setRegeLocationInfo(true);
            startLocation(listener);
        }else{
            startLocation(null);
        }
    }

    /**
     * App 默认定位方式接入方法
     * @param listener
     */
    public void startLocation(MyAppLocationListener listener){
        startLocation(MapType.eBaiDuMap,listener);
    }

    public void startLocation(MapType mapType,MyAppLocationListener listener){
        this.locationListener = listener;

        switch(mapType){
        case eBaiDuMap:
        default:
            BDLocationManager.getInstance().start(listener);
            break;
        case eGaoDeMap:
            GDLocationManager.getInstance().start(listener);
            break;
        }
        timer.start();
    }

    public void onLocationSussess(BDLocation location,MyAppLocationListener listener){
        LocationInfoUtil.setGPSInfo(location);
        long timeMills = System.currentTimeMillis();
        if(!TextUtils.isEmpty(location.getTime())){
            try{
               Calendar c = Calendar.getInstance();
               c.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(location.getTime()));
               timeMills =  c.getTimeInMillis();
            }catch(Exception ex){
            }
        }
        if(location.getLocType()==BDLocation.TypeNetWorkLocation)
            if(listener!=null) listener.setRegeLocationInfo(false);
        double[] point = LocationPointUtil.getAmapLocationFormBD(location.getLatitude(), location.getLongitude());
        onLocationSussess(timeMills,point[0],point[1],listener);
    }

    public void onLocationSussess(AMapLocation location,MyAppLocationListener listener){
        LocationInfoUtil.setGPSInfo(location);
        long timeMills = location.getTime();
        if(!TextUtils.isEmpty(location.getProvider())&&location.getProvider().contains("lbs"))
            if(listener!=null) listener.setRegeLocationInfo(false);
        onLocationSussess(timeMills,location.getLatitude(),location.getLongitude(),listener);
    }

    public void onLocationSussess(long timeMills,double lan,double lon,MyAppLocationListener listener){
        if(listener != null){
            //先返回位置,在返回位置信息,即[返回两次];
            listener.onLocation(timeMills,lan, lon);
            if(listener.isRegeLocationInfo()){
                getLocationInfo(lan, lon, listener);
            }else{
                listener.onLocation(GlobalInfo.getInstance().getGpsInfo());
            }
        }
        timer.cancel();
    }

    public void onLocationedFaild(MyAppLocationListener listener){
        double[] locs = getLastKnowLocation();
        if(listener != null){
            listener.onLocation(-1,locs[0], locs[1]);
        }
        timer.cancel();
    }

    private void getLocationInfo(final double lan,final double lon,final MyAppLocationListener listener) {
        GDGeoManager.getInstance().reverseGeocode(new LatLonPoint(lan, lon), new GDGeoManagerListener() {
            @Override
            public void onGeocodeStart() {
            }

            @Override
            public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
                if (i != 0 || regeocodeResult == null)
                    return;
                RegeocodeAddress address =  regeocodeResult.getRegeocodeAddress();
                if (address == null||TextUtils.isEmpty(address.getFormatAddress()))
                    return;

                DbGPSInfo gpsInfo = LocationInfoUtil.getGPSInfo(regeocodeResult);
                LocationInfoUtil.setGPSInfo(gpsInfo);
                if(listener!=null)
                    listener.onLocation(gpsInfo);
            }
        });
    }

    public double[] getLastKnowLocation(){
        BDLocation locBD = BDLocationManager.getInstance().getLastKnowLocation();
        if(locBD != null&&LocationPointUtil.isChinaLonLant(locBD.getLatitude(),locBD.getLongitude()))
            return LocationPointUtil.getAmapLocationFormBD(locBD.getLatitude(),locBD.getLongitude());

        AMapLocation locGD = GDLocationManager.getInstance().getLastKnowLocation();
        if(locGD != null&&LocationPointUtil.isChinaLonLant(locGD.getLatitude(),locGD.getLongitude()))
            return new double[]{locGD.getLatitude(),locGD.getLongitude()};

        DbGPSInfo gpsInfo = GlobalInfo.getInstance().getGpsInfo();
        if(gpsInfo!=null&&LocationPointUtil.isChinaLonLant(gpsInfo.getLatitude(),gpsInfo.getLongitude())){
            return new double[]{gpsInfo.getLatitude(), gpsInfo.getLongitude()};
        }

        startLocation(true);
        return  new double[]{0.0, 0.0};
    }

    private void getTimerLocation(){
        timer = new CountDownTimer(timeOutCacelLocation, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
            }

            @Override
            public void onFinish() {
                if(locationListener!=null){
                    onLocationedFaild(locationListener);
                }
            }
        };
    }

    //默认定位类,可不理会;
    protected class MyDefaultAppLocationInfoListener extends MyAppLocationListener{
        @Override
        public void onLocation(long timeMills,double lan, double lon) {
        }
        @Override
        public void onLocation(DbGPSInfo info) {
        }
    }
}
  1. MyAppLocationListener.java;
import com.idonoo.frame.dao.DbGPSInfo;
import com.idonoo.frame.types.MapType;

public abstract class MyAppLocationListener {
    public boolean isRegeLocationInfo = false;
    private MapType mapType;
    public boolean isRegeLocationInfo() {
        return isRegeLocationInfo;
    }
    public void setRegeLocationInfo(boolean isNeedRese) {
        this.isRegeLocationInfo = isNeedRese;
    }
    public MapType getMapType() {
        return mapType;
    }
    public void setMapType(MapType mapType) {
        this.mapType = mapType;
    }

    public abstract void onLocation(long timeMills,double lan, double lon);

    public abstract void onLocation(DbGPSInfo info);

}

代码基础使用方法

直接使用,最长定位时间为MyAppLocation中设定的8s,超过8s返回上次,或者返回0且在此进行定位请求;

MyAppLocation.getInstance().startLocation(true);//默认检索位置的详细信息,不返回给界面,默认后台存储具体信息入库;

先返回经纬度,后返回改经纬度的具体信息,在BaseActivity中添加改代码,在任何Activity可用;

public void startLocation(boolean isShowProgress,boolean isRegeInfo){
        if(isShowProgress)
            showProgress("获取位置...");
        MyAppLocationInfoListener listener = new MyAppLocationInfoListener();
        listener.setRegeLocationInfo(isRegeInfo);
        MyAppLocation.getInstance().startLocation(listener);
    }

    public void onLocationed(double lan,double lon) {
        dismissProgress();
    }

    public void onLocationed(DbGPSInfo info) {
        dismissProgress();
    }

附加一个系统定位的

package com.idonoo.shareCar.vendor.record;

import java.util.List;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.text.TextUtils;

import com.idonoo.frame.Frame;
import com.idonoo.frame.model.Locations;
import com.idonoo.frame.types.MapType;

/**
 * 系统定位
 * @author intbird
 *
 */
public class LocationAS {
    private LocationManager locationMangaerForGPS;
    private LocationManager locationMangaerForNetWork;
    private LocationManager locationMangaerForUncertain;
    private MySALocationListener locationListener;

    //minTime should be the primary tool to conserving battery life
    private int locTimemills = 2 * 60 * 1000;
    private int locMeters  = 300;

    public void setLocTimemills(int locTimemills) {
        this.locTimemills = locTimemills;
    }
    public void setLocMeters(int locMeters) {
        this.locMeters = locMeters;
    }

    public void start(LocationPointCallBack callBack){
        locationListener = new MySALocationListener(callBack);

        locationMangaerForUncertain = (LocationManager)Frame.getInstance().getAppContext().getSystemService(Context.LOCATION_SERVICE);
        locationMangaerForGPS = (LocationManager)Frame.getInstance().getAppContext().getSystemService(Context.LOCATION_SERVICE);
        locationMangaerForNetWork = (LocationManager)Frame.getInstance().getAppContext().getSystemService(Context.LOCATION_SERVICE);

        try{//RuntimeException - if the calling thread has no Looper //SecurityException - if no suitable permission is present
            locationMangaerForUncertain.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, locTimemills, locMeters, locationListener);
            locationMangaerForGPS.requestLocationUpdates(LocationManager.GPS_PROVIDER, locTimemills, locMeters, locationListener);
            locationMangaerForNetWork.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, locTimemills, locMeters, locationListener);
        }catch(Exception ex){

        }
    }

    private void startProvider(String currentProvider,boolean enableStatus){
        if(TextUtils.isEmpty(currentProvider)) return ;
        if(locationListener==null||locationMangaerForUncertain==null) return ;
        List<String> privoders = locationMangaerForUncertain.getAllProviders();
        if(privoders==null) return ;

        if(enableStatus==false){
             Location location=null;
             for(String privoder : privoders){
                if(privoder.equalsIgnoreCase(currentProvider)||TextUtils.isEmpty(privoder)) continue;

                if(privoder.equalsIgnoreCase(LocationManager.GPS_PROVIDER)){
                    try{
                        location = locationMangaerForGPS.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        locationMangaerForGPS.requestLocationUpdates(LocationManager.GPS_PROVIDER, locTimemills, locMeters, locationListener);
                    }catch(Exception ex){
                    }
                }
                else if(privoder.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)){
                    try{
                        location = locationMangaerForNetWork.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                        locationMangaerForNetWork.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, locTimemills, locMeters, locationListener);
                    }catch(Exception ex){
                    }
                }else {
                    try{
                        location = locationMangaerForUncertain.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
                        locationMangaerForUncertain.requestLocationUpdates(privoder,locTimemills, locMeters, locationListener);
                    }catch(Exception ex){
                    }
                }
             }
             if(location != null&&locationListener.mCallBack!=null){
                    locationListener.mCallBack.locted("AS",new Locations(location.getTime(),location.getTime(),location.getLongitude(),
                            location.getLatitude(), MapType.eAndServer.getValue(),location.getProvider()));
            }
        }
    }

    //the provider is disabled by the user, updates will stop.
    public void stop(){
        if(null!=locationListener&&null!=locationMangaerForGPS){
            locationMangaerForGPS.removeUpdates(locationListener);
            locationMangaerForNetWork.removeUpdates(locationListener);
            locationMangaerForUncertain.removeUpdates(locationListener);
        }
    }
    private class MySALocationListener implements LocationListener {
        private LocationPointCallBack mCallBack;
        public MySALocationListener(LocationPointCallBack callBack){
            this.mCallBack= callBack;
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
            startProvider(provider,true);
        }

        @Override
        public void onProviderDisabled(String provider) {
            startProvider(provider,false);
        }

        @Override
        public void onLocationChanged(Location location) {
            if(location != null){
                if(mCallBack != null && isCallBack(location.getTime())){
                    mCallBack.locted("AS",new Locations(location.getTime(),location.getTime(),location.getLongitude(),
                            location.getLatitude(), MapType.eAndServer.getValue(),location.getProvider()));
                }
            }
        }
    }
}

end;

时间: 2024-10-30 11:41:25

android:应用程序内定位处理,百度定位,高德定位,系统定位处理.的相关文章

Xamarin Android 应用程序内图标上数字提示

最近在用 Xamarin 做一个 Android 应用,打开应用时,如果有新消息,需要在应用内的 Toolbar 或者首页的图标上显示数字提示.在这里和大家分享一下实现方法,如果你有更新好的实现方法,欢迎分享. 类似推特客户端的新消息提醒 解决思路:把图标和数字提示文本放在 RelativeLayout 或 FrameLayout 内,把文本放在右上角. 实现代码: 新建一个 Xamain Android 项目,打天 Main.axml 文件,首先添加一下 Toolbar,<android.su

存储、读取——Android应用程序内置的文件夹

1.将数据存储到应用程序的文件夹,并读写 Context提供了两个方法,打开应用程序文件夹的I/O,若文件不存在则创建 FileInputStream openFileInputStream(String fileName); FileOuputStream openFileOutputStream(String fileName,int mode); mode: 1. MODE_APPEND: 追加方式存储 2. MODE_PRIVATE: 私有方式存储,其他应用无法访问 3. MODE_WO

如何利用 release 版本的 backtrace 来定位 android NDK 程序的崩溃位置

我们知道 android NDK 程序在崩溃时会生成一个 tombstone 的 backtrace (也可利用 ADB logcat 抓取),从这个 backtrace 中我们可以了解是哪个函数引发的崩溃,但是通常由于我们发布时都是 release 版,无法利用 backtrace 中的地址信息直接定位到源码和行号,当引发崩溃的错误不是很明显时,对于我们解决问题的帮助就不大. 这时通常我们是重编一个 debug 版本并设法重现 crash.这样做有个两个问题,一是如果我们不知道复现步骤,或者复

Android Studio之高德地图实现定位和3D地图显示

在应用开发中,地图开发是经常需要使用的"组件",国内比较出名的是就是百度地图和高德地图. 此博客讲的是高德地图实现定位和3D地图显示,并标注相应位置,话不多说,先看看效果,在上代码. 效果如图: 首先注册高德成为开发者(打开高德地图,点击底部的开发者平台),创建应用,按照要求填写相应信息,如下图: 途中包含了发布版的SHA1安全码和测试版SHA1安全码,两者的值可以看  博客 :Android Studio apk打包,keystore.jks文件生成,根据keystore密钥获取SH

Arcgis andoid开发之应用百度地图接口实现精准定位与显示

怀着激动.兴奋的心情,在这个漫天柳絮的季节写下了这片博文,为什么呢,因为困扰我很久的一个技术性的问题得到了解决,发次博文,供大家参观.学习,同时,也以慰藉我长期困扰的心情,好了,废话不再,言归正传,看看这到底是个什么东西? 首先,简单地介绍一下功能:1.离线地图的加载:2.GPS的定位与显示.文字比较模糊,看看实际的效果图: 功能其实很简单,下面解释一下实现思路: 1.布局 <?xml version="1.0" encoding="utf-8"?> &

百度地图开发之【定位】

在前面几次我们分别完成了数据检索和线路规划的功能,但是如果我们不知道自己位置,检索起来说是不是会很麻烦呢? 知道自己位置就可以根据自己的位置进行检索和路线规划. 定位服务 在读地图的定位服务是与基本地图服务分开的所以需要引入另外的so文件盒jar包,如果你选择的是复合包的话,只用一如so文件就OK了. 首先在清单文件中加上如下的服务 <service android:name="com.baidu.location.f" android:enabled="true&qu

百度地图V5.0地图定位

按照官方api一步一步写下来碰到的问题 mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类 mLocationClient.registerLocationListener( myListener ); //注册监听函数 LocationClientOption option = new LocationClientOption(); option.setLocationMode(L

如何利用【百度地图API】进行定位?非GPS定位

原文:如何利用[百度地图API]进行定位?非GPS定位 如果你可以上网,如果你有火狐浏览器,那么恭喜你.你能很容易使用以下代码进行定位! ------------------------------------------------------------------------------- 百度地图API是一套由JavaScript语言编写的应用程序接口,它能够帮助您在网站中构建功能丰富.交互性强的地图应用程序. 其中,有Geolocation这个类,可以帮助你进行定位. 它的原理是,利用

HTML5地理定位,百度地图API,知识点熟悉

判断浏览器的兼容问题: IE9+支持地理定位,FF Chrome新版支持地理定位  if (navigator.geolocation) { alert('支持地理定位'); } else { alert('不支持地理定位'); } 获取自己位置经纬度 <script> var x=document.getElementById("wrap"); function getLocation () { if (navigator.geolocation) { navigator