Android的时候到底是onLocationChanged称为 [英] Android when exactly is onLocationChanged called

查看:104
本文介绍了Android的时候到底是onLocationChanged称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎对我来说这是越来越称为第一次活动开始,刚过的onCreate,它就好像是叫随机时间间隔,我是否移动或不???

It seems for me it is getting called the first time the activity starts, just after onCreate, it then seems to be called at random intervals, whether I move or not???

无论是它只是自动调用,如果我有code这样的onCreate方法?

Regardless of that is it simply called automatically if I have code like this in the onCreate method?

locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();

是这样吗???

Is that right???

干杯, 迈克。

推荐答案

您的问题没有明确的initially.Your code和标题不匹配。我给的答案只有你的标题。

Your question is not clear initially.Your code and title are not matching. I am giving answer for your title only.

您必须注册地点监听你的位置管理,则仅onLocationChanged()会根据你注册时的位置监听器提供的设置来调用。

You have to register Location Listener for your Location Manager, then only onLocationChanged() will be called according the settings you supplied while registering location listener.

请参阅下面的code如何做到这一点。我用GPS供应商,您可以使用基于标准的也可以是任何供应商。

See below code how to do that. I used GPS Provider, you can use any provider based on criteria also.

LocationManger lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                // TODO Auto-generated method stub
            }
            @Override
            public void onProviderDisabled(String provider) {
                // TODO Auto-generated method stub
            }
            @Override
            public void onProviderEnabled(String provider) {
                // TODO Auto-generated method stub
            }
            @Override
            public void onStatusChanged(String provider, int status,
                    Bundle extras) {
                // TODO Auto-generated method stub
            }           
        });

来到你的问题,onLocationChanged()将在当前位置更新未与上个已知位置的匹配来调用。

Coming to your question, onLocationChanged() will be called if the current location update is not matching with last known location.

更新后的位置将每一个minTime改变(在我的情况下,1000毫秒),并且,如果设备移动minDistance依旧(在我的例中为0米)的距离。

The updated location will be changed for every minTime (in my case 1000 milli sec) and also if device moved minDistance (in my case 0 meters) distance.

我希望你能明白这一点。

I hope you will understand this.

这篇关于Android的时候到底是onLocationChanged称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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