Android Maps API v2更改MyLocation图标

Gyr*_*ope 26 android google-maps android-maps-v2

我想用我自己的图像替换Android Maps V2用于"我的位置"(小蓝点/箭头)的默认图标.我创建了自己的磁贴provider,它带来了一些主要是蓝色的地图,因此很难看到默认的"我的位置"图标.以前我会覆盖它的draw方法MyLocationOverlay,但是在新的api中似乎没有.任何帮助都会很棒!

编辑:我还需要图标才能旋转,就像箭头一样,取决于你面对的方式.所以我不能只使用正常marker:(基本上我只需要为该箭头创建自定义图像..

在此输入图像描述

更新 Hi All,Google Play的更新现在允许平面标记和标记旋转,这正是我所需要的.

Int*_*hep 29

我的简单解决方法就是禁用谷歌地图的"我的位置"

并使用我的图标在Map上创建ImageView,然后使用捕获ImageView

onClick和getMyLocation,onClick中的animateCamera

 this.mGoogleMap.getUiSettings().setMyLocationButtonEnabled(false);
 this.mGoogleMap.setMyLocationEnabled(true);
Run Code Online (Sandbox Code Playgroud)

.

@Override
public void onClick(final View v) {

    Location location = this.mGoogleMap.getMyLocation();

        if (location != null) {

            LatLng target = new LatLng(location.getLatitude(), location.getLongitude());
            CameraPosition position = this.mGoogleMap.getCameraPosition();

            Builder builder = new CameraPosition.Builder();
            builder.zoom(15);
            builder.target(target);

            this.mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(builder.build()));

          }    
}
Run Code Online (Sandbox Code Playgroud)


Gyr*_*ope 21

Google Play服务的最新更新现在允许您使用"平面"标记并旋转它们,这正是我所需要的.这是我实现它的方式的简单版本.我可以做一些优化和调整动画的工作,但它目前正在完成工作.欢迎任何反馈.

Marker mPositionMarker;
GoogleMap mMap;

@Override
public void onLocationChanged(Location location) {

    if (location == null)
        return;

    if (mPositionMarker == null) {

        mPositionMarker = mMap.addMarker(new MarkerOptions()
                .flat(true)
                .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.positionIndicator))
                .anchor(0.5f, 0.5f)
                .position(
                        new LatLng(location.getLatitude(), location
                                .getLongitude())));
    }

    animateMarker(mPositionMarker, location); // Helper method for smooth
                                                // animation

    mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location
            .getLatitude(), location.getLongitude())));

}

public void animateMarker(final Marker marker, final Location location) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    final LatLng startLatLng = marker.getPosition();
    final double startRotation = marker.getRotation();
    final long duration = 500;

    final Interpolator interpolator = new LinearInterpolator();

    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed
                    / duration);

            double lng = t * location.getLongitude() + (1 - t)
                    * startLatLng.longitude;
            double lat = t * location.getLatitude() + (1 - t)
                    * startLatLng.latitude;

            float rotation = (float) (t * location.getBearing() + (1 - t)
                    * startRotation);

            marker.setPosition(new LatLng(lat, lng));
            marker.setRotation(rotation);

            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            }
        }
    });
}
Run Code Online (Sandbox Code Playgroud)