Google Maps API get place text like on iframe map -


so have found couple of ways maps onto page, first version using iframe so:

<iframe src="https://www.google.com/maps/embed/v1/place?key=[apikey]&amp;q=place_id:[placeid]"></iframe> 

which gives marker following image name of place next marker:

enter image description here

however, isn't perfect has massive white box in top left , according many posts, unable remove it.

so thought try js route have following code:

var map = new google.maps.map(this, {   zoom: 15,   center: { lat: options.latitude, lng: options.longitude } });  marker = new google.maps.marker({   map: map,   title: options.title });  marker.setplace({   placeid: options.placeid,   location: { lat: options.latitude, lng: options.longitude } });  var infowindow = new google.maps.infowindow(   {     content: '<strong>' + options.title + '</strong><br />' + options.address   });  google.maps.event.addlistener(marker, 'click', function () {   infowindow.open(map, marker); }); 

where options filled in proper values. however, produces following map better doesn't have white box:

enter image description here

however, second map doesn't have shop text on map though using same place id first 1 is.

is there way change js code include place text in iframe version? have searched documentation , examples couldn't find setting this

you can add label map yourself. 1 option use infobox:

function addmaplabel(text, latlng, map) {   var labeltext = "<b>" + text + "</b>";    var myoptions = {     content: labeltext,     boxstyle: {       border: "none",       textalign: "center",       fontsize: "8pt",       width: "auto",       color: "#800000"     },     disableautopan: true,     pixeloffset: new google.maps.size(10, -10),     position: latlng,     closeboxurl: "",     ishidden: false,     pane: "mappane",     enableeventpropagation: true   };    var iblabel = new infobox(myoptions);   iblabel.open(map); } 

google maps javascript api v3 map label

proof of concept fiddle

code snippet:

function addmaplabel(text, latlng, map) {    var labeltext = "<b>" + text + "</b>";      var myoptions = {      content: labeltext,      boxstyle: {        border: "none",        textalign: "center",        fontsize: "8pt",        width: "auto",        color: "#800000"      },      disableautopan: true,      pixeloffset: new google.maps.size(10, -10),      position: latlng,      closeboxurl: "",      ishidden: false,      pane: "mappane",      enableeventpropagation: true    };      var iblabel = new infobox(myoptions);    iblabel.open(map);  }  var map;  var options = {    placeid: "chij68tmaatce0gry70pzdzq17u",    latitude: 53.7153659,    longitude: -1.8790866,    title: "dickies tiles",    address: "aachen way, halifax hx1 3nd, united kingdom"  }    function initialize() {    var map = new google.maps.map(document.getelementbyid("map_canvas"), {      zoom: 15,      center: {        lat: options.latitude,        lng: options.longitude      }    });      marker = new google.maps.marker({      map: map,      title: options.title    });      marker.setplace({      placeid: options.placeid,      location: {        lat: options.latitude,        lng: options.longitude      }    });      var infowindow = new google.maps.infowindow({      content: '<strong>' + options.title + '</strong><br />' + options.address    });      google.maps.event.addlistener(marker, 'click', function() {      infowindow.open(map, marker);    });    addmaplabel(options.title, new google.maps.latlng(options.latitude, options.longitude), map);  }  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>  <script src="https://cdn.rawgit.com/googlemaps/v3-utility-library/master/infobox/src/infobox.js"></script>  <div id="map_canvas"></div>


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -