javascript - How to hide points of interest google maps except my location? - Stack Overflow

I'm using Google Map API V3 and I noticed there are a lot of markers that are here even though I d

I'm using Google Map API V3 and I noticed there are a lot of markers that are here even though I don't need them. So I want to hide all other locations except mine or without losing my location title.

below is my code

HTML

<div id="map"></div>

Javascript

var map;
function initMap() {
    var myLocation = { lat: 52.5750833, lng: -0.2412917 };
    map = new google.maps.Map( document.getElementById('map'), {
        center: myLocation,
        zoom: 19,
        mapTypeControl: false
    }); 
}

I already use this code. this helps me but it also removes the location title called "Royal Square"

var noPoi = [
    {
        featureType: "poi",
        elementType: "labels",
        stylers: [
            { 
                visibility: "off" 
            }
        ]   
    }
];
map.setOptions({styles: noPoi});

I'm using Google Map API V3 and I noticed there are a lot of markers that are here even though I don't need them. So I want to hide all other locations except mine or without losing my location title.

below is my code

HTML

<div id="map"></div>

Javascript

var map;
function initMap() {
    var myLocation = { lat: 52.5750833, lng: -0.2412917 };
    map = new google.maps.Map( document.getElementById('map'), {
        center: myLocation,
        zoom: 19,
        mapTypeControl: false
    }); 
}

I already use this code. this helps me but it also removes the location title called "Royal Square"

var noPoi = [
    {
        featureType: "poi",
        elementType: "labels",
        stylers: [
            { 
                visibility: "off" 
            }
        ]   
    }
];
map.setOptions({styles: noPoi});
Share Improve this question edited Dec 1, 2021 at 16:21 Bhautik asked Apr 27, 2018 at 14:25 BhautikBhautik 11.3k3 gold badges18 silver badges40 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

If you only need "your" marker. Remove all the POI markers, add a marker for the place (POI) you want to appear.

proof of concept fiddle

code snippet:

function initMap() {
  var infowindow = new google.maps.InfoWindow();
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {
      lat: -33.8688,
      lng: 151.2195
    },
    zoom: 18
  });

  var RoyalSq = new google.maps.Marker({
    placeId: "ChIJvfdyRztP4DsRfSKksTGiGWs",
    position: {
      lat: 21.232947,
      lng: 72.864397
    },
    map: map
  });
  RoyalSq.addListener('click', function(evt) {
    infowindow.setContent('<div class="poi-info-window gm-style"> <div jstcache="2"> <div class="title full-width" >Royal Square</div> <div class="address"> <div class="address-line full-width">Uttran</div><div class="address-line full-width" >Surat, Gujarat 394105</div><div class="address-line full-width">India</div> </div> </div> <div style="display:none"></div> <div class="view-link"> <a target="_blank" href="https://maps.google./maps?ll=21.233067,72.864432&amp;z=20&amp;t=m&amp;hl=en-US&amp;gl=US&amp;mapclient=apiv3&amp;cid=7717377770793476733"> <span> View on Google Maps </span> </a> </div> </div>');
    infowindow.open(map, RoyalSq);
  })
  google.maps.event.trigger(RoyalSq, 'click');
  map.setCenter(RoyalSq.getPosition());
  var noPoi = [{
    featureType: "poi",
    elementType: "labels",

    stylers: [{
      visibility: "off"
    }]
  }];

  map.setOptions({
    styles: noPoi
  });
}
#map {
  height: 100%;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

.controls {
  background-color: #fff;
  border-radius: 2px;
  border: 1px solid transparent;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  font-family: Roboto;
  font-size: 15px;
  font-weight: 300;
  height: 29px;
  margin-left: 17px;
  margin-top: 10px;
  outline: none;
  padding: 0 11px 0 13px;
  text-overflow: ellipsis;
  width: 400px;
}

.controls:focus {
  border-color: #4d90fe;
}

.title {
  font-weight: bold;
}

#infowindow-content {
  display: none;
}

#map #infowindow-content {
  display: inline;
}
<div id="map"></div>
<script src="https://maps.googleapis./maps/api/js?libraries=places&callback=initMap&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk" async defer></script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744262733a4565715.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信