获取当前位置与GPS和WIFI [英] Get current position with GPS AND WIFI

查看:356
本文介绍了获取当前位置与GPS和WIFI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的GPS只获取用户的当前位置返回了一定的成绩。如在比利时,如果你在里面,大部分的时间你不能得到GPS的连接。所以,我想获得当前位置的无线连接。

我发现这个例子:获取当前位置(GPS / WIFI)

我不知道这行告诉选择哪个连接的设备。我猜这是这一个:字符串商= myLocationManager.getBestProvider(标准,真); ,我已经加入到我的code

当我检查什么是这里面,我总是得到一个空值,我不明白为什么。

我的code目前看起来是这样的:

 公共无效getOwnLngLat(){
LocationManager locationManager =(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
最后LocationListener的LocationListener的=新LocationListener的(){

公共无效onLocationChanged(位置定位){
    // TODO自动生成方法存根
    经度=+ location.getLongitude();
    纬度=+ location.getLatitude();
}

公共无效onProviderDisabled(字符串提供商){
    // TODO自动生成方法存根

}

公共无效onProviderEnabled(字符串提供商){
    // TODO自动生成方法存根

}

公共无效onStatusChanged(字符串商,INT地位,
                捆绑演员){
    // TODO自动生成方法存根

   }
};
locationManager.requestLocationUpdates(locationManager.getBestProvider(新标准(),TRUE),2000,10,LocationListener的);
}
 

解决方案

您使用locationmanagers getbestprovider方法,它只是获取的任何位置提供最能符合您的标准。 如果你想获得一个特定的位置提供再使用getProvider方法。的参数应该是getProviders方法的结果之一。 一些链接: http://developer.android.com/guide/topics/location /obtaining-user-location.html http://developer.android.com/reference/android/location/LocationManager.html

I'm currently using GPS only to get current location of the user to return certain results. As in Belgium, if you're inside, most of the time you can't get GPS-connection. So I want to get the current location with the wifi-connection.

I've found this example: get the current location (gps/wifi) But

I'm not sure which lines tell the device which connection to choose. I'm guessing it's this one: String provider = myLocationManager.getBestProvider(criteria,true); That I've to add to my code.

When I check what's inside of this, I always get a null-value, I don't quite understand why.

My code looks currently like this:

public void getOwnLngLat(){
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
final LocationListener locationListener = new LocationListener(){

public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub
    longitude="" + location.getLongitude();
    latitude="" + location.getLatitude();
}

public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub

}

public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub

}

public void onStatusChanged(String provider, int status,
                Bundle extras) {
    // TODO Auto-generated method stub

   }        
};
locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), 2000, 10, locationListener);
}

解决方案

you are using locationmanagers getbestprovider method which simply gets any location provider which most closely matches your criteria. if you want to get a specific location provider then use the getProvider method. the parameter should be one of the results of the getProviders method. some links: http://developer.android.com/guide/topics/location/obtaining-user-location.html http://developer.android.com/reference/android/location/LocationManager.html

这篇关于获取当前位置与GPS和WIFI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆