我正在使用osmdroid,我只是遇到了在地图上获取我的初始位置坐标的问题。
我可以在地图上获取位置,我可以获得在可运行的内部打印的初始位置。
有什么办法可以得到初始坐标吗?我不需要更新它们或任何东西..
我只需要它们,这样我就可以在初始位置和目的地之间设计一条路线....
任何帮助都会非常感谢!
这是我的代码;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Context ctx = getApplicationContext();
//important! set your user agent to prevent getting banned from the osm servers
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
setContentView(R.layout.activity_map);
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
IMapController mapController = mMapView.getController();
mapController.setZoom(13);
GeoPoint startPoint = new GeoPoint(52.167247, -6.888583);
Marker POI1 = new Marker(mMapView);
Marker POI2 = new Marker(mMapView);
Marker POI3 = new Marker(mMapView);
Marker POI4 = new Marker(mMapView);
POI1.setPosition(new GeoPoint(52.187668, -6.866953));
POI2.setPosition(new GeoPoint(52.124359, -6.926442));
POI3.setPosition(new GeoPoint(52.222310, -6.933613));
POI4.setPosition(new GeoPoint(52.221245, -6.830961));
List<OverlayItem> markers = null;
mMapView.getOverlays().add(POI1);
mMapView.getOverlays().add(POI2);
mMapView.getOverlays().add(POI3);
mMapView.getOverlays().add(POI4);
mapController.setCenter(startPoint);
//add
GpsMyLocationProvider provider = new GpsMyLocationProvider(this);
provider.addLocationSource(LocationManager.NETWORK_PROVIDER);
locationOverlay = new MyLocationNewOverlay(provider, mMapView);
locationOverlay.enableMyLocation();
locationOverlay.enableFollowLocation();
locationOverlay.runOnFirstFix(new Runnable() {
public void run() {
Log.d("MyTag", String.format("First location fix: %s", locationOverlay.getLastFix()));
}
});
mMapView.getOverlayManager().add(locationOverlay);
//System.out.println("hello joe: " + currentLocation.getLongitude() );
RoadManager roadManager = new OSRMRoadManager(this);
ArrayList<GeoPoint> wayPoints = new ArrayList<GeoPoint>();
wayPoints.add(startPoint);
GeoPoint endPoint = new GeoPoint(52.221245, -6.830961);
wayPoints.add(endPoint);
Road road = roadManager.getRoad(wayPoints);
if (road.mStatus != Road.STATUS_OK){
Toast.makeText(this, "Error when loading road", Toast.LENGTH_LONG).show();
}
Polyline roadOverlay = RoadManager.buildRoadOverlay(road);
mMapView.getOverlays().add(roadOverlay);
}
答案 0 :(得分:0)
我通过使用位置提供程序
解决了这个问题