我正试图给用户使用谷歌地图从一个位置到另一个位置的方向。 我正在使用代码波纹管,但我不知道为什么它不起作用。我无法弄清楚问题一切似乎正确。Android:从谷歌地图获取路线
final double latitude = 37.894404;
final double longitude = -122.0660386;
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
Location lastKnownLocation = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, true));
if(lastKnownLocation != null){
double lat = lastKnownLocation.getLatitude();
double longi = lastKnownLocation.getLongitude();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+lat+","+longi+"&daddr="+latitude+","+longitude));
startActivity(intent);
}else{
Toast.makeText(contactus.this,"Coudn't get provider", Toast.LENGTH_SHORT).show();
}
}
实际上,我在实际设备上运行此。我也试图给出经度和纬度,而不是当前的位置谷歌的uri,但它没有工作!所以我不认为获取当前位置是问题 – Mona