如何在Android中更改Google地图的颜色

问题描述 投票:3回答:3

在这里,我试图将谷歌地图的颜色从白色改为黑色,但没有得到一个好的解决方案。我尝试通过使用相对布局进行更改,但它隐藏了那部分,它不会改变GoogleMap的颜色。

            <fragment xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/map"
                class="com.google.android.gms.maps.MapFragment"
                android:layout_width="match_parent"
                android:layout_height="100dp" />
android google-maps android-maps-v2
3个回答
1
投票

去这里:https://mapstyle.withgoogle.com/ 找到你的风格,并获得json的风格价值和复制。 来到你的android地图项目资源,点击新文件,添加json并粘贴样式json值,如style_map.json,你的地图活动的onMapReady(GoogleMap googleMap)执行此操作:

mGoogleMap = googleMap;
MapStyleOptions mapStyleOptions = MapStyleOptions.loadRawResourceStyle(this, R.raw.style_json);
mGoogleMap.setMapStyle(mapStyleOptions);

这个对我有用 :)


0
投票

我通过将qtml文件放入assets文件夹中运行Html中的Google Map的WebView文件得到了它的解决方案。我用下面的代码来显示

<!DOCTYPE html>
<html>
<head>
<title>Panoramio Layer</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
    html, body, #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
    }
    #panel {
    position: absolute;
    top: 5px;
    left: 50%;
    margin-left: -180px;
    z-index: 5;
    background-color: #fff;
    padding: 5px;
    border: 1px solid #999;
    }
    #photo-panel {
    background: #fff;
    padding: 5px;
    overflow-y: auto;
    overflow-x: hidden;
    width: 300px;
    max-height: 300px;
    font-size: 14px;
    font-family: Arial;
    border: 1px solid #ccc;
    box-shadow: -2px 2px 2px rgba(33, 33, 33, 0.4);
    display: none;
    }
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=panoramio"></script>
<script>
function initializeGmaps() {
var LatLng = {lat: 28.596979, lng: 77.326742};
var mapCanvas = document.getElementById('google-map');
var mapOptions = {
center : LatLng,
scrollwheel : false,
zoom : 14,
mapTypeId : google.maps.MapTypeId.ROADMAP,
backgroundColor: 'none',
styles : [{
stylers: [
{ invert_lightness: true },
{ hue: '#666' },
{ saturation: -100 },
{ lightness: -0 },
{ visibility: 'simplified' }
]
}]
}
var map = new google.maps.Map(mapCanvas, mapOptions);
var marker = new google.maps.Marker({
position: LatLng,
map: map,
icon: '<?=base_url();?>images/marker.png',
title: 'Advisorymandi.com Pvt. Ltd.'
});
}
google.maps.event.addDomListener(window, 'load', initializeGmaps);

</script>
</head>
<body>
<ul id="photo-panel">
<li><strong>Photos clicked</strong></li>
</ul>
<div id="google-map" class="youplay-gmaps" style=" height: 450px; width: 100%;"></div>
</body>
</html>

-1
投票

为此,你必须使用谷歌地图v3库。见documentation

© www.soinside.com 2019 - 2024. All rights reserved.