GPS Location manuell setzen

J

java4life

Neues Mitglied
2
Hi,

ich wollte gerne das GPS-Modul des Smartphones ansprechen. Nun folgendes Problem: was ist,wenn GPS zum Beispiel dauerhaft deaktiviert ist, ich aber manuell neue Positionen setzen will -also eine Art Emulation.

Der Code sieht folgendermaßen aus:
Code:
private LocationManager myManager;
    private TextView tv;


    /********************************************************************** 
     * Activity overrides below 
     **********************************************************************/
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // get a handle to our TextView so we can write to it later
        tv = (TextView) findViewById(R.id.TextView01);

        // set up the LocationManager
        myManager = (LocationManager) getSystemService(LOCATION_SERVICE);   
    }

    @Override
    protected void onDestroy() {
        stopListening();
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        stopListening();
        super.onPause();
    }

    @Override
    protected void onResume() {
        startListening();
        super.onResume();
    }
    /**********************************************************************
     * helpers for starting/stopping monitoring of GPS changes below 
     **********************************************************************/
    private void startListening() {
        myManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 
            0, 
            0, 
            this
        );
    }

    private void stopListening() {
        if (myManager != null)
            myManager.removeUpdates(this);
    }
    /**********************************************************************
     * LocationListener overrides below 
     **********************************************************************/
    @Override
    public void onLocationChanged(Location location) {
        // we got new location info. lets display it in the textview
        String s = "";
        s += "Time: "        + location.getTime() + "\n";
        s += "\tLatitude:  " + location.getLatitude()  + "\n";
        s += "\tLongitude: " + location.getLongitude() + "\n";
        s += "\tAccuracy:  " + location.getAccuracy()  + "\n";

        tv.setText(s);
    }    

    @Override
    public void onProviderDisabled(String provider) {}    

    @Override
    public void onProviderEnabled(String provider) {}    

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {}
Jetzt habe ich zum Beispiel eine Liste aus Koordinaten und möchte diese "ablaufen". Dann müsste ich doch der "onLocationChanged"-Methode eine neue Location übergeben. Es soll also so Aussehen,als ob die Location vom GPS-Modul des Handys kommt...(sie wird aber manuell gesetzt)

Also zum Beispiel:
Code:
Location locationA = new Location("blubb");
locationA.setLatitude("2141");
locationA.setLongitude("453");
Aber wie mache ich das, dass der LocationManager die Änderung mitbekommt?
Danke schon mal für eure Hilfe!
 
Schau dir mal LocationManager.addTestProvider(), LocationManager.setTestProviderEnable(), LocationManager.setTestProviderLocation() an.
Das dürfte wohl das sein was du suchst. In den Einstellungen wirst du wohl die Option "allow fake locations" aktivieren müssen, oder so ähnlich.
 
  • Danke
Reaktionen: java4life
Hat sehr geholfen! Der TestProvider war mir bisher auch gar nicht geläufig, aber es klappt alles so wie es soll. Danke!
 

Ähnliche Themen

A
Antworten
1
Aufrufe
633
swa00
swa00
W
  • WuDiDong
Antworten
3
Aufrufe
765
jogimuc
J
H
Antworten
2
Aufrufe
928
swa00
swa00
Zurück
Oben Unten