Den*_*nis 0 android android-maps-v2
我正在尝试调用方法requestLocationUpdates,但最终我收到一条错误消息"无法解析方法".我认为这是因为"这个"论点,但我不确定.我导入了LocationListener,但它没有帮助我.
这是我的代码部分:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainMap extends ActionBarActivity implements LocationListener {
private void addMarker(){
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if(status!= ConnectionResult.SUCCESS){ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}else { // Google Play Services are available
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
onLocationChanged(location);
}
// troubles here
locationManager.requestLocationUpdates(provider, 20000, 10, this);
}
}
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
}
}
Run Code Online (Sandbox Code Playgroud)
您正在LocationListener从错误的包导入.您似乎将其导入为:
com.google.android.gms.location.LocationListener
Run Code Online (Sandbox Code Playgroud)
但requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener)方法是这种类型的最后一个参数:
android.location.LocationListener
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到.
将import语句更改为load android.location.LocationListener应该可以解决问题.
| 归档时间: |
|
| 查看次数: |
10501 次 |
| 最近记录: |