目前,我正在我的android应用程序中使用谷歌地图v2,我遇到了一个地图配色方案定制的问题。我在web上看到了这一点,这里使用javascript,https://developers.google.com/maps/customize和http://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 );
但是没有找到android地图的解决方案,有什么建议吗?
发布于 2017-03-21 14:07:17
从此处创建样式
https://mapstyle.withgoogle.com/
然后将该json保存在RAW文件夹下,然后在代码中调用该样式,如下所示
MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(getActivity(), R.raw.my_map_style);
googleMap.setMapStyle(style);
发布于 2013-05-13 18:58:33
这在Android API v2中是不可能的。唯一可以更改的是映射类型。
我只能建议在gmaps-api-issues上发布一个功能请求。
编辑:posted on gmaps-api-issues。
发布于 2015-09-17 21:06:05
您可以通过使用MapBox的接口来实现这一点。首先,注册一个帐户,根据需要设计地图,然后获取MapID和访问令牌。
接下来,复制这个类
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;
}
} }
现在,在您的活动中,一旦地图准备就绪:
String myMapID = "yourMapID";
String accesToken = "yourAccesToken";
MapBoxOnlineTileProvider provider = new MapBoxOnlineTileProvider(myMapID, accesToken);
map.addTileOverlay(new TileOverlayOptions()
.tileProvider(provider));
结果:
https://stackoverflow.com/questions/16520121
复制相似问题