如何从Google地图

时间:2015-11-02 22:16:37

标签: javascript google-maps google-maps-api-3

我希望能够从我的谷歌地图中删除垂直和水平虚线。创建地图时我需要做些什么来删除它们?

enter image description here

var mapOptions = {
  zoom: "",
  zoomControl: "",
  center: "",
  disableDefaultUI: "",
  draggable: "",
  styles: "",
  disableDoubleClickZoom: ""
}

mapOptions.zoom = 1;
mapOptions.zoomControl = false;
mapOptions.center = new window.google.maps.LatLng(mapCoordinates.latitude, mapCoordinates.longitude);;
mapOptions.disableDefaultUI = true;
mapOptions.draggable = false;
mapOptions.styles = "";
mapOptions.disableDoubleClickZoom = true;

$googlemap = new window.google.maps.Map(document.getElementById('map-canvas'), mapOptions);

2 个答案:

答案 0 :(得分:3)

如果您只想删除赤道和国际日期行。看起来您需要删除所有管理几何。

{
  "featureType": "administrative",
  "elementType": "geometry",
  "stylers": [
    { "visibility": "off" }
  ]
}

这也会删除所有其他管理边界,要将它们放回去,您需要单独添加它们:

  {
    "featureType": "administrative.country",
    "elementType": "geometry.stroke",
    "stylers": [
      { "visibility": "on" }
    ]
  },{
    "featureType": "administrative.province",
    "elementType": "geometry.stroke",
    "stylers": [
      { "visibility": "on" }
    ]
  },{
    "featureType": "administrative.locality",
    "elementType": "geometry.stroke",
    "stylers": [
      { "visibility": "on" }
    ]
  },{
    "featureType": "administrative.neighborhood",
    "elementType": "geometry.stroke",
    "stylers": [
      { "visibility": "on" }
    ]
  },{
    "featureType": "administrative.land_parcel",
    "elementType": "geometry.stroke",
    "stylers": [
      { "visibility": "on" }
    ]
  }

代码段



var geocoder;
var map;

function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 2,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      styles: [{
        "featureType": "administrative",
        "elementType": "geometry",
        "stylers": [{
          "visibility": "off"
        }]
      }, {
        "featureType": "administrative.country",
        "elementType": "geometry.stroke",
        "stylers": [{
          "visibility": "on"
        }]
      }, {
        "featureType": "administrative.province",
        "elementType": "geometry.stroke",
        "stylers": [{
          "visibility": "on"
        }]
      }, {
        "featureType": "administrative.locality",
        "elementType": "geometry.stroke",
        "stylers": [{
          "visibility": "on"
        }]
      }, {
        "featureType": "administrative.neighborhood",
        "elementType": "geometry.stroke",
        "stylers": [{
          "visibility": "on"
        }]
      }, {
        "featureType": "administrative.land_parcel",
        "elementType": "geometry.stroke",
        "stylers": [{
          "visibility": "on"
        }]
      }]
    });


}
google.maps.event.addDomListener(window, "load", initialize);

html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}

<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您必须创建样式化地图以删除赤道和国际日期行。但请注意,它也可以删除其他管理元素。

// Map style CODE after create $googlemap
var cleanStyle = [{
    featureType: "administrative",
    elementType: "geometry",
    stylers: [
      { visibility: "off" }
    ]
}];

// Create a new Styled Map
var styledMap = new google.maps.StyledMapType(cleanStyle);
// Attach the styledMap with the main map
$googlemap.mapTypes.set('cleanMap', styledMap);
// Set the new styled map as active
$googlemap.setMapTypeId('cleanMap'); 

这是example