谷歌地图Android API v2和当前位置
我正在使用Jellybean4.2并在我的设备上进行测试 如何单击myLocationButton获取当前位置 getMYLocation在使用网络提供程序时返回null 我正在使用LocationManager获取当前位置并参考Google文档谷歌地图Android API v2和当前位置,android,maps,google-maps-android-api-2,Android,Maps,Google Maps Android Api 2,我正在使用Jellybean4.2并在我的设备上进行测试 如何单击myLocationButton获取当前位置 getMYLocation在使用网络提供程序时返回null 我正在使用LocationManager获取当前位置并参考Google文档 在此之后,单击MyLocatiionButton不会带来任何更改您是否在清单中设置了所有权限? 此外,您还必须启用定位服务(状态栏中的gps图标是否显示?)。 设备获取位置需要一些时间,因此请查看是否调用onLocationChanged 您是否在清
在此之后,单击MyLocatiionButton不会带来任何更改您是否在清单中设置了所有权限? 此外,您还必须启用定位服务(状态栏中的gps图标是否显示?)。
设备获取位置需要一些时间,因此请查看是否调用onLocationChanged 您是否在清单中设置了所有权限? 此外,您还必须启用定位服务(状态栏中的gps图标是否显示?)。
设备获取位置需要一些时间,因此请查看是否调用onLocationChanged 使用此代码Id它确实有效
private LocationManager locationManager;
private Location location;
private boolean hasGpsProvider, hasNetwrokProvider;
public Location getLocation(Context mContext) {
if (locationManager == null) {
locationManager = (LocationManager) mContext
.getSystemService(Context.LOCATION_SERVICE);
}
hasGpsProvider = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
hasNetwrokProvider = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (hasGpsProvider) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 100, locationListenerGps);
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
return location;
}
if (hasNetwrokProvider) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 100,
locationListenerNetwork);
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
return location;
}
return location;
}
打电话
if (location != null) {
lat = location.getLatitude();
lng = location.getLongitude();
}
使用此代码Id,它确实有效
private LocationManager locationManager;
private Location location;
private boolean hasGpsProvider, hasNetwrokProvider;
public Location getLocation(Context mContext) {
if (locationManager == null) {
locationManager = (LocationManager) mContext
.getSystemService(Context.LOCATION_SERVICE);
}
hasGpsProvider = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
hasNetwrokProvider = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (hasGpsProvider) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 100, locationListenerGps);
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
return location;
}
if (hasNetwrokProvider) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 100,
locationListenerNetwork);
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
return location;
}
return location;
}
打电话
if (location != null) {
lat = location.getLatitude();
lng = location.getLongitude();
}
您需要将LocationSource添加到地图片段中。请参阅以获取离散示例。您需要将LocationSource添加到地图片段中。请参阅一个单独的示例。基本上,您应该调用Google Directions API接收道路方向坐标(多个Latlng点),然后在它们之间绘制一条多段线
用户可以选择概述多段线或腿部和台阶。基本上,您应该调用Google Directions API接收道路方向坐标(多个板条点),然后在它们之间绘制一条多段线
U用户可以使用概述\ U多段线或支腿和步骤。我已按照文档中的规定设置了所有权限,gps图标也显示在状态barI中,我已按照文档中的规定设置了所有权限,gps图标也显示在状态BARRE中。正在设备或模拟器上使用?将在以后进行更改,并且通知您稍后将进行更改并通知您