forked from opensciencemap/vtm
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add location layer and Samples example opensciencemap#171
- Loading branch information
Showing
7 changed files
with
153 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
vtm-android-example/src/org/oscim/android/test/LocationActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2016 devemux86 | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.oscim.android.test; | ||
|
||
import android.content.Context; | ||
import android.location.Location; | ||
import android.location.LocationListener; | ||
import android.location.LocationManager; | ||
import android.os.Bundle; | ||
|
||
import org.oscim.core.MapPosition; | ||
import org.oscim.layers.LocationLayer; | ||
|
||
public class LocationActivity extends SimpleMapActivity implements LocationListener { | ||
private LocationLayer locationLayer; | ||
private LocationManager locationManager; | ||
private final MapPosition mapPosition = new MapPosition(); | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); | ||
|
||
locationLayer = new LocationLayer(mMap); | ||
mMap.layers().add(locationLayer); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
enableAvailableProviders(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
|
||
locationManager.removeUpdates(this); | ||
} | ||
|
||
@Override | ||
public void onLocationChanged(Location location) { | ||
locationLayer.setPosition(location.getLatitude(), location.getLongitude(), location.getAccuracy()); | ||
|
||
// Follow location | ||
mMap.getMapPosition(mapPosition); | ||
mapPosition.setPosition(location.getLatitude(), location.getLongitude()); | ||
mMap.setMapPosition(mapPosition); | ||
} | ||
|
||
@Override | ||
public void onProviderDisabled(String provider) { | ||
} | ||
|
||
@Override | ||
public void onProviderEnabled(String provider) { | ||
} | ||
|
||
@Override | ||
public void onStatusChanged(String provider, int status, Bundle extras) { | ||
} | ||
|
||
private void enableAvailableProviders() { | ||
locationManager.removeUpdates(this); | ||
|
||
for (String provider : locationManager.getProviders(true)) { | ||
if (LocationManager.GPS_PROVIDER.equals(provider) | ||
|| LocationManager.NETWORK_PROVIDER.equals(provider)) { | ||
locationManager.requestLocationUpdates(provider, 0, 0, this); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2013 Ahmad Saleem | ||
* Copyright 2013 Hannes Janetzek | ||
* Copyright 2016 devemux86 | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.oscim.app.location; | ||
|
||
import org.oscim.layers.LocationLayer; | ||
import org.oscim.map.Map; | ||
|
||
class LocationLayerImpl extends LocationLayer { | ||
private final Compass mCompass; | ||
|
||
LocationLayerImpl(Map map, Compass compass) { | ||
super(map); | ||
mCompass = compass; | ||
|
||
locationRenderer.setCallback(compass); | ||
} | ||
|
||
@Override | ||
public void setEnabled(boolean enabled) { | ||
super.setEnabled(enabled); | ||
|
||
mCompass.setEnabled(enabled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters