Is there a way to use only AutoComplete in the Places library in Google Maps API (V3)?

Asked 1 years ago, Updated 1 years ago, 78 views

In Google Maps API (v3), I want to use AutoComplete, so I have enabled the Places library.
You can click on places other than markers on the map that have nothing to do with it.
Is there a way to use AutoComplete only or not to click anywhere other than the marker?

Enter a description of the image here

api google-maps

2022-09-30 20:28

1 Answers

I think it is possible to hide the landmark label.

function initialize(){
  // create map 
  varmap = new google.maps.Map( document.getElementById('map-canvas'), {
    center: {
      lat:35.683373,
      lng —139.769212
    },
    zoom —18
  });
  // define map type
  map.mapTypes.set('nopoi', new google.maps.StyledMapType([{{
    featureType: "poi",
    elementType: "labels",
    styleers:[{
      visibility:"off"
    }]
  }],   {
    name: "NO POI"
  }));
  // apply maptype
  map.setMapTypeId('nopoi');

  // test —search restaurant around marunouchi
  var service = new google.maps.places.PlacesService(map);
  service.search({
    location: new google.maps.LatLng (35.683373, 139.769212),
    radius: '500',
    query: 'restaurant'
  }, function(results, status){
    for(var_r=0;_r<results.length;++_r){
      // create marker
      new google.maps.Marker({
        position:results[_r].geometry.location,
        map —map,
        title:results[_r].name
      });
    }
  });
};
initialize();
#map-canvas{
  height —400px;
  width —500px;
}
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=true_or_false"></script>
<divid="map-canvas"></div>
//create map 
varmap = new google.maps.Map( document.getElementById('map-canvas'), {
    center: {
        lat:35.683373,
        lng —139.769212
    },
    zoom —18
});
// define map type
map.mapTypes.set('nopoi', new google.maps.StyledMapType([{{ 
    featureType: "poi", 
    elementType: "labels", 
    styleers:[{
        visibility:"off"
    }] 
}], {
    name: "NO POI"
}));
// apply maptype
map.setMapTypeId('nopoi');


2022-09-30 20:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.