没有找到关于如何实现这一点的完整指南。我有:
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
//My location changed
myPosition = new LatLng(location.getLatitude(), location.getLatitude());
date = new Date();
//Update marker
myMarker.snippet(new Timestamp(date.getTime()).toString());
myMarker.position(myPosition);
//Update map
//updateMap();
//Move camera
mMap.moveCamera(CameraUpdateFactory.newLatLng(myPosition));
//mMap.animateCamera(CameraUpdateFactory.zoomTo(17));
//Show dialog
boxUpdate.show();
Log.i("Map Location", "New cache for location retrived!");
}
@Override
public void onProviderDisabled(String provider) {
//Required, but not in use
}
@Override
public void onProviderEnabled(String provider) {
//Required, but not in use
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
//Required, but not in use
}
});
那么,我需要做些什么才能让它发挥作用? 我只启用了WiFi,但我认为缓存是完全空的,不会以某种方式填满。我是否遗漏了一些必要的东西让它听完了?
答案 0 :(得分:1)
如果您想使用wifi获取位置,请更改此..
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener()
到
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener()
让我知道是否还不行。
SO强迫你:)