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是我的onlocation更改绘制路径代码,但它有一些bug。它会画出一半的路径并且不会继续绘制agian?任何人都可以帮助我或建议我更好的方法吗?
答案 0 :(得分:0)
与“蓝点”位置完全匹配,使用
map.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
...
});
使用LocationManager
永远不会产生与OnMyLocationChangeListener
相同的结果,因为它使用的是其他提供商:"gps"
或"network"
与"fused"
}。