首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在安卓系统中定制谷歌地图V2的配色方案

在安卓系统中定制谷歌地图V2的配色方案
EN

Stack Overflow用户
提问于 2013-05-13 18:41:17
回答 5查看 8.2K关注 0票数 3

目前,我正在我的android应用程序中使用谷歌地图v2,我遇到了一个地图配色方案定制的问题。我在web上看到了这一点,这里使用javascript,https://developers.google.com/maps/customizehttp://jsfiddle.net/SQvej/,js中的一些例子。

代码语言:javascript
运行
复制
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 );

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

EN

回答 5

Stack Overflow用户

发布于 2017-03-21 14:07:17

从此处创建样式

https://mapstyle.withgoogle.com/

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

代码语言:javascript
运行
复制
MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(getActivity(), R.raw.my_map_style);
        googleMap.setMapStyle(style);
票数 5
EN

Stack Overflow用户

发布于 2013-05-13 18:58:33

这在Android API v2中是不可能的。唯一可以更改的是映射类型。

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

编辑:posted on gmaps-api-issues

票数 3
EN

Stack Overflow用户

发布于 2015-09-17 21:06:05

您可以通过使用MapBox的接口来实现这一点。首先,注册一个帐户,根据需要设计地图,然后获取MapID访问令牌

接下来,复制这个类

代码语言:javascript
运行
复制
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;
    }
} }

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

代码语言:javascript
运行
复制
String myMapID = "yourMapID";
String accesToken = "yourAccesToken";
MapBoxOnlineTileProvider provider = new   MapBoxOnlineTileProvider(myMapID, accesToken);
map.addTileOverlay(new TileOverlayOptions()
                .tileProvider(provider));

结果:

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16520121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档