3

目前,我正在我的 android 应用程序中使用 google maps v2,并且遇到了地图配色方案定制的问题。我看到它可以在 web 中使用 javascript https://developers.google.com/maps/customizehttp://jsfiddle.net/SQvej/ js 中的一些示例

var settingsItemsMap = {
zoom: 12,
center: new google.maps.LatLng(40.768516981, -73.96927308),
zoomControlOptions: {
  style: google.maps.ZoomControlStyle.LARGE
},
styles:[
    { featureType: "water", stylers: [ { hue: "#F4B741"} ] },
    { featureType: "road", stylers: [ { hue: "#ff0000" } ] }
],
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'), settingsItemsMap );

但没有找到安卓地图的解决方案,有什么建议吗?

4

5 回答 5

5

从这里创造风格

在此处输入图像描述

https://mapstyle.withgoogle.com/

然后将该json保存在RAW文件夹下,然后像这样在代码中调用该样式

MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(getActivity(), R.raw.my_map_style);
        googleMap.setMapStyle(style);
于 2017-03-21T06:07:16.527 回答
3

这在 Android API v2 中是不可能的。您唯一可以更改的是地图类型。

我只能建议在gmaps-api-issues上发布功能请求。

编辑:发布在 gmaps-api-issues 上

于 2013-05-13T10:58:33.067 回答
3

您可以通过使用MapBox的 API 来实现这一点。首先,注册一个账号,按照你需要的方式设计地图,然后获取MapIDAccess Token


接下来,复制这个类

public class MapBoxOnlineTileProvider extends UrlTileProvider {

public final String TAG = this.getClass().getCanonicalName();
private static final String FORMAT;

static {
    FORMAT = "%s://api.tiles.mapbox.com/v4/%s/%d/%d/%d.png?access_token=%s";
}


private boolean mHttpsEnabled;
private String mMapIdentifier;
private String mAccessToken;


public MapBoxOnlineTileProvider(String mapIdentifier, String accessToken) {
    this(mapIdentifier, accessToken, false);
}

public MapBoxOnlineTileProvider(String mapIdentifier, String accessToken, boolean https) {
    super(256, 256);

    this.mHttpsEnabled = https;
    this.mMapIdentifier = mapIdentifier;
    this.mAccessToken = accessToken;
}


/**
 * The MapBox map identifier being used by this provider.
 *
 * @return the MapBox map identifier being used by this provider.
 */
public String getMapIdentifier() {
    return this.mMapIdentifier;
}

/**
 * Sets the identifier of the MapBox hosted map you wish to use.
 *
 * @param aMapIdentifier the identifier of the map.
 */
public void setMapIdentifier(String aMapIdentifier) {
    this.mMapIdentifier = aMapIdentifier;
}

/**
 * Whether this provider will use HTTPS when requesting tiles.
 *
 * @return {@link true} if HTTPS is enabled on this provider.
 */
public boolean isHttpsEnabled() {
    return this.mHttpsEnabled;
}

/**
 * Sets whether this provider should use HTTPS when requesting tiles.
 *
 * @param enabled
 */
public void setHttpsEnabled(boolean enabled) {
    this.mHttpsEnabled = enabled;
}

/**
 * The MapBox Acces Token found in Account Settings.
 */
public String getAccessToken() {
    return mAccessToken;
}

public void setAccessToken(String mAccessToken) {
    this.mAccessToken = mAccessToken;
}

@Override
public URL getTileUrl(int x, int y, int z) {
    try {
        String protocol = this.mHttpsEnabled ? "https" : "http";
        final String url = String.format(FORMAT,
                protocol, this.mMapIdentifier, z, x, y, this.mAccessToken);
        Log.d(TAG, url);
        return new URL(url);
    } catch (MalformedURLException e) {
        return null;
    }
} }

现在,在您的 Activity 中,一旦地图准备就绪:

String myMapID = "yourMapID";
String accesToken = "yourAccesToken";
MapBoxOnlineTileProvider provider = new   MapBoxOnlineTileProvider(myMapID, accesToken);
map.addTileOverlay(new TileOverlayOptions()
                .tileProvider(provider));

结果: 在此处输入图像描述

于 2015-09-17T13:06:05.103 回答
1

如果要求只是调暗或更改地图的整体颜色,那么您可以使用图块叠加。这将在地图上创建部分透明的图层(在本例中为绿色)。它位于图块的正上方,因此标记和其他对象不受影响。

@Override
public void onMapReady(GoogleMap googleMap) {
    TileProvider coordTileProvider = new CoordTileProvider(getActivity());
    map.addTileOverlay(new TileOverlayOptions().tileProvider(coordTileProvider));       
}

课程CoordTileProvider是:

public static class CoordTileProvider implements TileProvider {

    private static final int TILE_SIZE_DP = 256;

    private final float mScaleFactor;

    private final Bitmap mBorderTile;

    public CoordTileProvider(Context context) {
        /* Scale factor based on density, with a 0.2 multiplier to increase tile generation
         * speed */
        mScaleFactor = context.getResources().getDisplayMetrics().density * 0.2f;
        Paint paint = new Paint();
        paint.setColor(Color.argb(150,200,255,200));
        mBorderTile = Bitmap.createBitmap((int) (TILE_SIZE_DP * mScaleFactor),
                (int) (TILE_SIZE_DP * mScaleFactor), android.graphics.Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(mBorderTile);
        canvas.drawRect(0, 0, TILE_SIZE_DP * mScaleFactor, TILE_SIZE_DP * mScaleFactor,
                paint);
    }

    @Override
    public Tile getTile(int x, int y, int zoom) {
        Bitmap coordTile = drawTileCoords(x, y, zoom);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        coordTile.compress(Bitmap.CompressFormat.PNG, 0, stream);
        byte[] bitmapData = stream.toByteArray();
        return new Tile((int) (TILE_SIZE_DP * mScaleFactor),
                (int) (TILE_SIZE_DP * mScaleFactor), bitmapData);
    }

    private Bitmap drawTileCoords(int x, int y, int zoom) {
        Bitmap copy = null;
        synchronized (mBorderTile) {
            copy = mBorderTile.copy(android.graphics.Bitmap.Config.ARGB_8888, true);
        }
        return copy;
    }
}
于 2016-09-18T07:43:10.927 回答
0

您只能更改地图样式。

这个链接告诉你,如何在地图上设置样式。

这个链接告诉你如何为谷歌地图创建样式。

于 2017-04-21T07:28:01.790 回答