无法解析符号OnMyLocationClickListener

时间:2019-03-06 09:20:04

标签: android google-maps google-maps-markers

当我使用此方法时然后错误:即使我已经使用OnMapReadyCallback实现了此方法,也无法解析符号OnMyLocationClickListener,并且gradle依赖关系还可以。

private GoogleMap.OnMyLocationClickListener onMyLocationClickListener =
    new GoogleMap.OnMyLocationClickListener() {
        @Override
        public void onMyLocationClick(@NonNull Location location) {

        }
    };

MapsActivity.java 显示最后一个方法的本活动无法解析符号。

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
SupportMapFragment mapFragment;
private GoogleMap mMap;
private GoogleMap.OnCameraIdleListener onCameraIdleListener;
private TextView resutText;
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT < 22)
        setStatusBarTranslucent(false);
    else
        setStatusBarTranslucent(true);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    resutText = (TextView) findViewById(R.id.dragg_result);
    mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    configureCameraIdle();
}
private void configureCameraIdle() {....}

@Override
public void onMapReady(GoogleMap googleMap) {...}

protected void setStatusBarTranslucent(boolean makeTranslucent) {..}

private GoogleMap.OnMyLocationButtonClickListener onMyLocationButtonClickListener =
        new GoogleMap.OnMyLocationButtonClickListener() {
            @Override
            public boolean onMyLocationButtonClick() {
                mMap.setMinZoomPreference(15);
                return false;
            }
        };
private GoogleMap.OnMyLocationClickListener onMyLocationClickListener =
        new GoogleMap.OnMyLocationClickListener() {
            @Override
            public void onMyLocationClick(@NonNull Location location) {
                mMap.setMinZoomPreference(12);
                CircleOptions circleOptions = new CircleOptions();
                circleOptions.center(new LatLng(location.getLatitude(),
                location.getLongitude()));
                circleOptions.radius(200);
                circleOptions.fillColor(Color.RED);
                circleOptions.strokeWidth(6);
                mMap.addCircle(circleOptions);
            }
        };
}

依赖项

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.google.android.gms:play-services-maps:11.0.4'

testCompile 'junit:junit:4.12'
}

1 个答案:

答案 0 :(得分:0)

OnMyLocationClickListener API可从Play服务地图版本SELECT docnumb1, sum FROM Table1 a left JOIN Table2 b ON a.docnumb1 = b.docnumb2 and a.value=b.value where b.docnumb2 is null

获得

解决方案:将gradle文件中的Play Services Map依赖项版本更改为11.4.0或更高。最新版本为11.4.0

16.1.0

选择您的依赖版本here