2014-01-16 3 views
3

전 혼란 스럽기 때문에 누구나 도울 수 있는지 궁금합니다 ... 모든 코드를 첨부했습니다. XMPP 서버에 위치를보고하고 장치의 현재 위도/경도를 기록하는 백그라운드 서비스를 설정했습니다. 모든 것이 멋지게 작동하며 오늘 밤 내 장비를 가져와 내 여행 계획을 세웁니다. 그러나 사무실로 RDP를 보내면 매분 본사에보고되는 위도/경도가 실제로 장치가 내 책상에 앉았을 때와 동일하다는 것을 알았습니다.Android Geo 백그라운드 서비스의 위치는 항상 동일한 lat lng를보고합니다.

네트워크 제공 업체와 Wi-Fi가 충돌 할 수 있다고 생각하는 기기에서 Wi-Fi를 사용 중지했지만 변경 사항이 표시되지 않습니다.

누구든지 도와 주시면 정말 감사하겠습니다. 왜냐하면 내가 뭘 잘못하고 있는지 알 수 없기 때문이야. Google과 다양한 위치 정보 예제를 확인한 결과 코드를 잘 볼 수 있습니다.

감사합니다.

package com.goosesys.gooselib.GeoLocation; 


/* 
* GeoLocation Class 
* GooseLib 
* 
* Used to access coarse and fine geo-location metrics based on the devices' last known location 
* 
* PERMISSIONS REQUIRED: 
* INTERNET, ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION 
*/ 
import com.goosesys.gooselib.Logging; 

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

public class GeoLocation implements LocationListener 
{ 
private LocationManager locationManager = null; 
private String provider = ""; 
@SuppressWarnings("unused") 
private double latitude = 0; 
@SuppressWarnings("unused") 
private double longitude = 0; 
@SuppressWarnings("unused") 
private Context context = null; 

public GeoLocation(Context context) 
{ 
    // used to add dialog prompts to the main activity 
    this.context = context; 
    locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE); 
    Criteria criteria = new Criteria(); 
    provider = locationManager.getBestProvider(criteria, false);   
    Location location = locationManager.getLastKnownLocation(provider); 

    if (location != null) 
    { 
     Logging.Info("GooseLib", "GeoLocation - provider [" + provider + "] has been selected"); 
     onLocationChanged(location); 
    } 
    else 
    { 
     locationManager = getLocationUpdates(); 
     Logging.Warning("GooseLib", "GeoLocation - Location not available"); 
    } 
} 

/* 
* Returns the location manager as an object after calling for location updates 
*/ 
public LocationManager getLocationUpdates() 
{ 
    locationManager.requestLocationUpdates(provider, 100, 1, this); 

    return locationManager; 
} 

/* 
* return the latitude of the current devices' location - last known location 
*/ 
public double getLatitude() 
{ 
    double lat = 0; 
    try 
    { 
     lat = locationManager.getLastKnownLocation(provider).getLatitude(); 
    } 
    catch(NullPointerException e) 
    { 
     e.printStackTrace(); 
    } 

    return lat; 
} 

/* 
* returns the longitude of the current devices' location - last known location 
*/ 
public double getLongitude() 
{ 
    double lng = 0; 
    try 
    { 
     lng = locationManager.getLastKnownLocation(provider).getLongitude();    
    } 
    catch(NullPointerException e) 
    { 
     e.printStackTrace(); 
    } 

    return lng; 
} 

@Override 
public void onLocationChanged(Location location) 
{ 
    this.latitude = location.getLatitude(); 
    this.longitude = location.getLongitude(); 
} 

@Override 
public void onProviderDisabled(String arg0) 
{ 
    Logging.Warning("GooseLib", "GeoLocation - Provider Disabled [" + provider + "]"); 
} 

@Override 
public void onProviderEnabled(String arg0) 
{ 
    Logging.Info("GooseLib", "GeoLocation - Provider Enabled [" + provider + "]"); 
} 

@Override 
public void onStatusChanged(String arg0, int arg1, Bundle arg2) 
{  
    // We don't need to worry about this method - just yet 
} 


} 

지형에 대한 백그라운드 서비스가 XMPP에 게시됩니다.

package com.goosesys.dta_pta_test; 

import org.jivesoftware.smack.packet.Message; 

import android.app.IntentService; 
import android.content.Intent; 
import com.google.gson.Gson; 
import com.goosesys.gooselib.GeoLocation.GeoLocation; 
import com.goosesys.gooselib.Transactions.Geo; 
import com.goosesys.gooselib.Transactions.MessageType; 
import com.goosesys.gooselib.Transactions.XMPPTransaction; 
import com.goosesys.gooselib.Utilities.AppSettings; 
import com.goosesys.gooselib.Utilities.Utility; 

public class BGGeoProc extends IntentService 
{ 

public BGGeoProc() 
{ 
    super("BGGeoProc"); 
} 

public BGGeoProc(String name) 
{ 
    super("BGGeoProc"); 
} 

public void updateLocation() 
{ 
    GeoLocation gl = new GeoLocation(getApplicationContext()); 
    double lng = gl.getLongitude(); 
    double lat = gl.getLatitude(); 

    MessageType mt = new MessageType(MessageType.Type.GEO); 
    Geo g = new Geo(lng, lat); 
    XMPPTransaction<Object> trans = new XMPPTransaction<Object>(mt, g); 

    Message m = new Message(); 
    m.setTo(AppSettings.BOT_NAME); 
    m.setFrom(Utility.getAndroidID(getApplicationContext())); 
    m.setBody(new Gson().toJson(trans)); 

    Intent s = new Intent(getApplicationContext(), XMPPIntentService.class); 
    s.putExtra(XMPPIntentService.MESSAGEDATA, new Gson().toJson(m)); 
    startService(s); 
} 

@Override 
protected void onHandleIntent(Intent intent) 
{   
    // Worker thread area // 
    updateLocation(); 
} 
} 

그리고 난 원래 당신이 실제로 어떤 위치를 받고되지 않은 것 같습니다

<!-- PERMISSION ACCESS --> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" /> 

답변

1

주 활동

private void startGeoLocationSender() 
{ 
    // do some work here 
    Calendar cal = Calendar.getInstance(); 

    Intent i = new Intent(this, BGGeoProc.class); 
    PendingIntent pintent = PendingIntent.getService(this, 0, i, 0); 

    Logging.Info(AppSettings.APP_TAG, "Setting Alarm Manager for BGGeoProc"); 

    // create an alarm manager to hook into system wide calendar 
    AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE); 
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 
      AppSettings.COLLECTOR_PROC_1_MINS, pintent);   
} 

권한에서 (1 분 간격) 서비스를 시작하는 방법 당신이 getLastKnownLocation()로 전화 할 때 당신이 알고있는 마지막 위치를 당신에게 줄 때 업데이트됩니다. ACCESS_COARSE_LOCATIONACCESS_FINE_LOCATION 권한이 있는지 확인하고 장치 설정에서 GPS가 사용 설정되어 있는지도 확인하십시오.

+0

내가 원래 생각 했었지만 내가 어디로 잘못 가고 있는지 알 수 없다. 내 권한을 넣는 것을 잊어 버렸기 때문에 내 게시물을 편집했습니다. 비즈니스 앱이기 때문에 대부분을 포함 시켰습니다. – LokiSinclair

+0

제공자를 얻는 곳에서 Log 문을 입력하고 어느 것이 다시 돌아 오는 지 확인하십시오. 또는 최상의 공급자를 선택하는 대신 두 공급자의 업데이트 수신 대기를 요청할 수도 있습니다. – CaseyB

+0

특정 GPS가 필요합니다. 따라서 해당 제공 업체에 연결하여 업데이트를 수신하도록 요청했습니다. 당신의 도움을 주셔서 감사합니다. – LokiSinclair