在固定的时间间隔获取GPS导航定位的Andr​​oid? [英] Get GPS navigation location in a fixed interval of time, android?

查看:288
本文介绍了在固定的时间间隔获取GPS导航定位的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧这里去我的应用程序是一个排序GPS追踪器应用程序,你可以说的。

Okay here it goes my app is sort of a GPS tracker app you can say.

如果用户从源到目的地旅行,我想直到用户到达目的地5-7分钟后,它的GPS定位说,并保持发送位置到指定号码的短信。

If the user is travelling from source to destination, i want to get its GPS location say after 5-7 minutes until the user has reached the destination and also keep send text messages of that position to a specified number.

所以我的问题,我怎样才能得到用户的位置,他已经关闭了申请后,发送短信?

So my question how can i get user's location and send message after he has closed the application?

用户将填写源和目的地在我的活动,然后点击一个按钮发送短信和应用程序关闭。

The user will fill in the source and destination in my activity and then click a button to send text message and the application closes.

我想这可以使用服务类机器人的解决...但我真的不知道我该如何使用呢?

I guess this can be solved with using service class of android...But i really didn't understood how can i use it?

推荐答案

使用 requestLocationUpdates() 的LocationManager 类在一定的时间间隔获取的GPS位置。看看<一个href=\"http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates%28java.lang.String,%20long,%20float,%20android.location.LocationListener%29\"相对=nofollow>这供您参考。

Use requestLocationUpdates() of LocationManager class for getting GPS location in certain time interval. Look into this for your reference.

请参阅以下code片断这将每1分钟取纬度和longitutude用户的当前位置。

See the following code snippet which would fetch user's current location in latitude and longitutude in every 1 min.

public Location getLocation() { 
    try { 
            locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); 
             // getting GPS status 
            isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
        // if GPS Enabled get lat/long using GPS Services 
        if (isGPSEnabled) {
            if (location == null) { 
                locationManager.requestLocationUpdates( 
                LocationManager.GPS_PROVIDER, 
                MIN_TIME_BW_UPDATES, 
                MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 

                    if (locationManager != null) { 
                    location = locationManager 
                    .getLastKnownLocation (LocationManager.GPS_PROVIDER); 
                    if (location != null) { 
                    latitude = location.getLatitude(); 
                    longitude = location.getLongitude(); 
                  } 
                } 
        } 
    } 
} catch (Exception e) { 
        e.printStackTrace(); 
        } 
        return location; 
    } 

获得后的纬度经度使用地理codeR 来获得详细的地址。

After getting the the Latitude and Longitude use Geocoder to get detailed address.

public List<Address> getCurrentAddress(){
    List<Address> addresses = new ArrayList<Address>();
    Geocoder gcd = new Geocoder(mContext,Locale.getDefault());
    try {
        addresses = gcd.getFromLocation(latitude, longitude, 1);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return addresses;
}

编辑:

做到以上functionalitie在延伸服务类,以便它跟踪用户位置eventhough的APPLN低于样品closed.c,

Do all the above functionalitie in a class that extends Service so that it tracks user location eventhough the appln is closed.c below for sample,

public class LocationTracker extends Service implements LocationListener{
     \\your code here
 }

这篇关于在固定的时间间隔获取GPS导航定位的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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