Can I increase the accuracy of my starting position
? 我marker always catch
的near position point
起点而不是起点。
以下是我的编码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
mgr = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria(); // Position Supporter Standard
bestProvider = mgr.getBestProvider(criteria, true); // Choose the Best
// Positon
Location location = mgr.getLastKnownLocation(bestProvider);
latitude1 = gps.getLatitude(location);
longitude1 = gps.getLongitude(location);
// Getting reference to SupportMapFragment of the activity_main
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
// Getting Map for the SupportMapFragment
map = fm.getMap();
// Enable MyLocation Button in the Map
map.setMyLocationEnabled(true);
} // OnCreate
// start from second page
protected void onStart() {
super.onStart();
loadMap();
}
// Marker first point
private void loadMap() {
// latitude1 = gps.getLatitude(location);
// longitude1 = gps.getLongitude(location);
LatLng position = new LatLng(latitude1, longitude1);
Toast.makeText(getApplicationContext(),
"LOADlat1:" + latitude1 + " / " + "LOADlog1:" + longitude1,
Toast.LENGTH_LONG).show();
// Instantiating MarkerOptions class
MarkerOptions options = new MarkerOptions();
// Setting position for the MarkerOptions
options.position(position);
// add marker
map.addMarker(options);
Log.i("Running+", "Options3: " + String.valueOf(position));
Log.i("Running+", "Options3: " + String.valueOf(options));
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
map = fm.getMap();
map.setMyLocationEnabled(true);
}
这是我的标记功能问题吗?任何人都可以帮我解决这个问题吗?
×××我的位置绘制路径代码×××
LocationListener onLocationChange = new LocationListener(){
@Override
public void onLocationChanged(Location location) {
if (location != null) {
Toast.makeText(getApplicationContext(), "Location NO EQUAL NULL AND START!", Toast.LENGTH_LONG).show();
GPSTracker1 gps2;
gps2 = new GPSTracker1(MainActivity2.this);
latitude2 = gps2.getLatitude();
longitude2 = gps2.getLongitude();
str_origin = "origin="+ latitude1 +","+ longitude1;
//Log.i("Running+", "Origin Status: " + str_origin);
// Destination of route
String str_dest2 = "destination="+ latitude2 +","+ longitude2;
//Log.i("LOCATION+", "Destination Status: " + latitude2 + ", " + longitude2);
// Sensor enabled
String sensor = "sensor=false";
// Building the parameters to the web service
String parameters = str_origin+"&"+str_dest2+"&"+sensor;
// Output format
String output = "json";
// Building the url to the web service
String url2 = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters;
//Log.i("Running+", "Map Get Location: " + url);
DownloadTask downloadTask2 = new DownloadTask();
downloadTask2.execute(url2);
Toast.makeText(getApplicationContext(), "Location Change 123!!", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "lat1:" + latitude1 + " / " + "log1:" + longitude1, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "lat2:" + latitude2 + " / " + "log2:" + longitude2, Toast.LENGTH_LONG).show();
// Getting reference to SupportMapFragment of the activity_main
SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
// Getting Map for the SupportMapFragment
map = fm.getMap();
// Enable MyLocation Button in the Map
map.setMyLocationEnabled(true);
Toast.makeText(getApplicationContext(), "Location Change Map!!", Toast.LENGTH_LONG).show();
}
}
public void onProviderDisabled(String arg0) {
}
public void onProviderEnabled(String arg0) {
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
}
};
我已经可以从两个固定点绘制路径,但我想做实时行走并绘制你行走的路径。Upper 是我的定位更改绘制路径代码,但它有一些错误。它将把路径画到一半,并且不会继续画下去吗?任何人都可以帮助我或建议我更好的方法来做到这一点吗?