Dav*_*id 48 gps android dictionary tracking
最近我把android开发作为一种爱好,并且正在寻找开发一个可以使用Google Maps查找和跟踪用户位置的应用程序.
一旦应用程序具有GPS锁定,应用程序就可以通过使用覆盖类绘制路径来跟踪其移动.
我见过像Mytracks这样的类似应用程序是开源的但是现在它们对我来说太复杂了.
理想情况下,我喜欢创建一个看起来像这样的应用程序

他是我的代码,没有进口.
我要做的是创建一系列地理点.每次位置更改时,都会创建一个新的地理点.然后我尝试使用for循环迭代每个geopoint并在它们之间绘制路径.
public class Tracking extends MapActivity implements LocationListener {
LocationManager locman;
LocationListener loclis;
Location Location;
private MapView map;
List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();
private MapController controller;
String provider = LocationManager.GPS_PROVIDER;
double lat;
double lon;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
initMapView();
initMyLocation();
locman = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// locman.requestLocationUpdates(provider,60000, 100,loclis);
// Location = locman.getLastKnownLocation(provider);
}
/** Find and initialize the map view. */
private void initMapView() {
map = (MapView) findViewById(R.id.map);
controller = map.getController();
map.setSatellite(false);
map.setBuiltInZoomControls(true);
}
/** Find Current Position on Map. */
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
overlay.enableCompass(); // does not work in emulator
overlay.runOnFirstFix(new Runnable() {
public void run() {
// Zoom in to current location
controller.setZoom(24);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}
@Override
public void onLocationChanged(Location location) {
if (Location != null) {
lat = Location.getLatitude();
lon = Location.getLongitude();
GeoPoint New_geopoint = new GeoPoint((int) (lat * 1e6),
(int) (lon * 1e6));
controller.animateTo(New_geopoint);
}
}
class MyOverlay extends Overlay {
public MyOverlay() {
}
public void draw(Canvas canvas, MapView mapv, boolean shadow) {
super.draw(canvas, mapv, shadow);
Projection projection = map.getProjection();
Path p = new Path();
for (int i = 0; i < geoPointsArray.size(); i++) {
if (i == geoPointsArray.size() - 1) {
break;
}
Point from = new Point();
Point to = new Point();
projection.toPixels(geoPointsArray.get(i), from);
projection.toPixels(geoPointsArray.get(i + 1), to);
p.moveTo(from.x, from.y);
p.lineTo(to.x, to.y);
}
Paint mPaint = new Paint();
mPaint.setStyle(Style.STROKE);
mPaint.setColor(0xFFFF0000);
mPaint.setAntiAlias(true);
canvas.drawPath(p, mPaint);
super.draw(canvas, map, shadow);
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序运行正常没有错误,但没有绘制路径,位置点只是随着我的移动而移动.
任何帮助将不胜感激谢谢.
chi*_*jib 22
您可以在此处获得Android移动应用程序open-gpstracker的源代码.
您可以使用SVN客户端应用程序或通过Git签出代码:
调试源代码肯定会对您有所帮助.
| 归档时间: |
|
| 查看次数: |
179916 次 |
| 最近记录: |