我想将Android Studio映射中的蓝点更改为箭头

时间:2018-07-15 13:44:11

标签: java android eclipse android-studio mobile

我想将您在Android Studio中Google Maps中的位置的默认图标更改为另一个图标。

默认图标是蓝色圆圈,谢谢。

1 个答案:

答案 0 :(得分:1)

解决方法是setMyLocationEnabled(false),以使该圆圈消失并使用手动获取最后一个位置 GoogleApiClient。

 mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(LocationServices.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
        mGoogleApiClient.connect();
        locationCallback = new LocationCallback() {
            @Override
            public void onLocationResult(LocationResult locationResult) {
                super.onLocationResult(locationResult);
                try {
                    lat = locationResult.getLastLocation().getLatitude();
                    lng = locationResult.getLastLocation().getLongitude();
googleMap.addMarker(new MarkerOptions().position(new LatLng(lat, lng))                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker_red)));






                } catch (Exception e) {
                }

            }

            @Override
            public void onLocationAvailability(LocationAvailability locationAvailability) {
                super.onLocationAvailability(locationAvailability);
            }
        };

在您的onConnected方法中:

 @Override
public void onConnected(@Nullable Bundle bundle) {

    LocationServices.getFusedLocationProviderClient(LocationActivity.this)
            .requestLocationUpdates(
                    getLocationRequest(), locationCallback, null);


}

其中的getLocationRequest:

private LocationRequest getLocationRequest() {
        mLocationRequest = LocationRequest.create();
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        mLocationRequest.setInterval(1000);
        return mLocationRequest;
    }