2012-03-02 68 views
0

我想使用GPS_PROVIDER點擊按鈕,找到當前位置的GPS座標。點擊'A'位置的按鈕後,我將關閉應用程序並轉到地點B並再次單擊該按鈕以獲取B座標。我怎樣才能做到這一點 ?我必須定義一個響應位置更新的偵聽器嗎?點擊按鈕後我如何在不同位置獲得GPS座標

+0

可能重複[我如何獲得當前GPS位置在編程的Android?](http://stackoverflow.com/questions/1513485/怎麼辦-I-GET-的電流-GPS定位,編程功能於機器人) – JasonMArcher 2014-09-29 18:16:20

回答

0

可以使用用於提取GPS數據下面的代碼,

package com.gpsexample.location; 
import android.location.Location; 
import android.location.LocationListener; 
import android.os.Bundle; 

public class LocListener implements LocationListener 
{ 
    private static double lat =0.0; 
    private static double lon = 0.0; 
    private static double alt = 0.0; 
    private static double speed = 0.0; 

    public static double getLat() 
    { 
     return lat; 
    } 

    public static double getLon() 
    { 
     return lon; 
    } 

    public static double getAlt() 
    { 
     return alt; 
    } 

    public static double getSpeed() 
    { 
     return speed; 
    } 

    @Override 
    public void onLocationChanged(Location location) 
    { 
     lat = location.getLatitude(); 
     lon = location.getLongitude(); 
     alt = location.getAltitude(); 
     speed = location.getSpeed(); 
    } 

    @Override 
    public void onProviderDisabled(String provider) {} 
    @Override 
    public void onProviderEnabled(String provider) {} 
    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) {} 
} 
相關問題