Hiding Empty Strings On Google Maps Info Window - google-maps

I am using Google Maps to plot a number of pins and am having problems hiding empty strings within the info window.
All locations have a name and address but then there are 3 fields which will not necessarily all have a value.
These are:
telephone number
email address
website
var markersOnMap = [{
title: "Location One",
placeName: "Location One",
address: "Address",
telephone: "01234567890",
website: "http://somewebaddress.com",
emailaddress: "",
LatLng: [{
lat: 40.4319077,
lng: 116.5703749
}]
}];
I then put the information into a variable to output it.
var contentString = '<div id="content"><p>' + markersOnMap[i].placeName + '</p><p>' + markersOnMap[i].address + '</p><p>T: ' + markersOnMap[i].telephone + '</p><p>' + markersOnMap[i].website + '</p><p><a href=mailto:"' + markersOnMap[i].emailaddress + '>' + markersOnMap[i].emailaddress + '</a></p></div>';
In the example above, Location One, I would like to hide the email address as it does not have a value.
How do I check if the value of those strings are empty and then not output them on a per location basis.
If anyone can provide any assistance, that would be great.

You could use proper var and ternary operator (or if ) for check each content and set the proper html dinamic string code
aPlaceName = (markersOnMap[i].placeName !='' ? '<p>' + markersOnMap[i].placeName + '</p>' :'');
aAddress = (markersOnMap[i].address !='' ? '<p>' + markersOnMap[i].placeName + '</p>' :'');7
...
and build the contentString using the var
var contentString = '<div id="content">' + aPlaceName + aAddress..... +'</div>';

One option would be to build the contentString incrementally if the pieces exist:
var contentString = '<div id="content">'
if (!!markersOnMap[i].placeName)
contentString += '<p>' + markersOnMap[i].placeName + '</p>';
if (!!markersOnMap[i].address)
contentString += '<p>' + markersOnMap[i].address + '</p>';
if (!!markersOnMap[i].telephone)
contentString += '<p>T: ' + markersOnMap[i].telephone + '</p>';
if (!!markersOnMap[i].website)
contentString += '<p>' + markersOnMap[i].website + '</p>';
if (!!markersOnMap[i].emailaddress)
contentString += '<p><a href=mailto:"' + markersOnMap[i].emailaddress + '>' + markersOnMap[i].emailaddress + '</a></p>';
contentString += '</div>';
proof of concept fiddle
code snippet:
// This example displays a marker at the center of Australia.
// When the user clicks the marker, an info window opens.
var markersOnMap = [{
title: "Location One",
placeName: "Location One",
address: "Address",
telephone: "01234567890",
website: "http://somewebaddress.com",
emailaddress: "",
LatLng: [{
lat: 40.4319077,
lng: 116.5703749
}]
},
{
title: "Location Two",
placeName: "Location Two",
address: "Address2",
emailaddress: "",
LatLng: [{
lat: 40.432,
lng: 116.58
}]
}
];
function initMap() {
var uluru = {
lat: -25.363,
lng: 131.044
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: uluru
});
var infoWindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markersOnMap.length; i++) {
var marker = new google.maps.Marker({
position: markersOnMap[i].LatLng[0],
map: map
});
bounds.extend(marker.getPosition());
marker.addListener('click', (function(i) {
return function(evt) {
var contentString = '<div id="content">'
if (!!markersOnMap[i].placeName)
contentString += '<p>' + markersOnMap[i].placeName + '</p>';
if (!!markersOnMap[i].address)
contentString += '<p>' + markersOnMap[i].address + '</p>';
if (!!markersOnMap[i].telephone)
contentString += '<p>T: ' + markersOnMap[i].telephone + '</p>';
if (!!markersOnMap[i].website)
contentString += '<p>' + markersOnMap[i].website + '</p>';
if (!!markersOnMap[i].emailaddress)
contentString += '<p><a href=mailto:"' + markersOnMap[i].emailaddress + '>' + markersOnMap[i].emailaddress + '</a></p>';
contentString += '</div>';
infoWindow.setContent(contentString);
infoWindow.open(map, this);
}
})(i))
}
map.fitBounds(bounds);
var contentString = '<div id="content">' +
'<div id="siteNotice">' +
'</div>' +
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>' +
'<div id="bodyContent">' +
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the ' +
'Northern Territory, central Australia. It lies 335 km (208 mi) ' +
'south west of the nearest large town, Alice Springs; 450 km ' +
'(280 mi) by road. Kata Tjuta and Uluru are the two major ' +
'features of the Uluru - Kata Tjuta National Park. Uluru is ' +
'sacred to the Pitjantjatjara and Yankunytjatjara, the ' +
'Aboriginal people of the area. It has many springs, waterholes, ' +
'rock caves and ancient paintings. Uluru is listed as a World ' +
'Heritage Site.</p>' +
'<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">' +
'https://en.wikipedia.org/w/index.php?title=Uluru</a> ' +
'(last visited June 22, 2009).</p>' +
'</div>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: uluru,
map: map,
title: 'Uluru (Ayers Rock)'
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap">
</script>

Related

Open Google Maps API info window on page load

I use the Google Maps & Google Places API the show my business data on a map. Actually the info window opens when i click the map marker but my goal is, that the infowindow opens on page load.
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails(request, function(place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
/* place.formatted_address + '<br />' + */
place.address_components[1].long_name + ' ' + place.address_components[0].long_name + '<br />' +
place.address_components[6].long_name + ' ' + place.address_components[2].long_name + '<br />' +
place.rating + place.user_ratings_total + '</div>');
infowindow.open(map, this);
});
}
});
You should move the code for info window and marker in main area
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' +
/* place.formatted_address + '<br />' + */
place.address_components[1].long_name + ' ' + place.address_components[0].long_name + '<br />' +
place.address_components[6].long_name + ' ' + place.address_components[2].long_name + '<br />' +
place.rating + place.user_ratings_total + '</div>');
infowindow.open(map, marker);

Google Map place card reposition

i'm trying to use a google embed iframe on the site the problem is i want to place it on the right side i'm using the API google but i cant seem to make it to the right location instead its going on the center please.Im on whole day figuring out this issues i'm using the &wloc=true on the append iframe. these are my codes below.here is my jsfiddle. please advise.
This is what i tried using geocoding. but the problem is that its always center, i want to put it on the top right because i want to overlay the left side with some div with an opacity effect. From the default embed the placard (bubble) will only post on the top left side. i dont want it to go on back it would be nice if i can reposition them on the top right.I'm also using the script base on the API.I've tried to alter its css but it doesnt let me overwrite it.
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Info windows</title>
</head>
<body>
<div id="map"></div>
<script>
// This example displays a marker at the center of Australia.
// When the user clicks the marker, an info window opens.
/*
geocoder = new google.maps.Geocoder();
var address = 'Level 1, 416 Mt Alexander Road, Ascot Vale VIC 3032';
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.SATELLITE,
zoom: 9
});
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var request = {
location: results[0].geometry.location,
// radius: 50000,
// name: 'ski',
//keyword: 'mountain',
type: ['ROADMAP']
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
else {
//alert("Geocode was not successful for the following reason: " + status);
}
});
return false;
*/
function initMap() {
var uluru = {lat: -25.363 , lng: 131.044};
var uluru = {lat: -27.4649562 , lng: 153.0261663};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: uluru
});
var contentString = '<div id="content" >'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
'<div id="bodyContent">'+
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park. Uluru is '+
'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
'Aboriginal people of the area. It has many springs, waterholes, '+
'rock caves and ancient paintings. Uluru is listed as a World '+
'Heritage Site.</p>'+
'<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
'(last visited June 22, 2009).</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: uluru,
map: map,
title: 'Uluru (Ayers Rock)'
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
infowindow.open(map,marker);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCQBbeAhgxa9nSQAdEFXJuLmNLFyANHdSo &callback=initMap">
</script>
</body>
</html>
You could add a div as a control in that upper right hand corner, populate it with the content appropriate to the marker when the marker is clicked (or put it there when the map loads).
marker.addListener('click', function() {
document.getElementById('infowindow').innerHTML = contentString;
document.getElementById('infowindow').style.display = "block";
});
// Create a div to hold the control.
var controlDiv = document.createElement('div');
// Set CSS for the control border
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = '#fff';
controlUI.style.border = '2px solid #fff';
controlUI.style.cursor = 'pointer';
controlUI.style.marginBottom = '22px';
controlUI.style.textAlign = 'center';
controlUI.title = 'Click to recenter the map';
controlDiv.appendChild(controlUI);
controlUI.appendChild(document.getElementById('infowindow'));
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);
proof of concept fiddle
function initMap() {
var uluru = {
lat: -27.4649562,
lng: 153.0261663
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: uluru,
fullscreenControl: false
});
var contentString = '<div id="content" >' +
'<div id="siteNotice">' +
'</div>' +
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>' +
'<div id="bodyContent">' +
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the ' +
'Northern Territory, central Australia. It lies 335 km (208 mi) ' +
'south west of the nearest large town, Alice Springs; 450 km ' +
'(280 mi) by road. Kata Tjuta and Uluru are the two major ' +
'features of the Uluru - Kata Tjuta National Park. Uluru is ' +
'sacred to the Pitjantjatjara and Yankunytjatjara, the ' +
'Aboriginal people of the area. It has many springs, waterholes, ' +
'rock caves and ancient paintings. Uluru is listed as a World ' +
'Heritage Site.</p>' +
'<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">' +
'https://en.wikipedia.org/w/index.php?title=Uluru</a> ' +
'(last visited June 22, 2009).</p>' +
'</div>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: uluru,
map: map,
title: 'Uluru (Ayers Rock)'
});
marker.addListener('click', function() {
document.getElementById('infowindow').innerHTML = contentString;
document.getElementById('infowindow').style.display = "block";
});
google.maps.event.trigger(marker, 'click');
// Create a div to hold the control.
var controlDiv = document.createElement('div');
// Set CSS for the control border
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = '#fff';
controlUI.style.border = '2px solid #fff';
controlUI.style.cursor = 'pointer';
controlUI.style.marginBottom = '22px';
controlUI.style.textAlign = 'center';
controlUI.title = 'Click to recenter the map';
controlDiv.appendChild(controlUI);
controlUI.appendChild(document.getElementById('infowindow'));
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);
}
#map {
height: 100%;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
#infowindow {
height: 100px;
width: 300px;
overflow: auto;
display: none;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Info windows</title>
</head>
<body>
<div id="map"></div>
<div id="infowindow"></div>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCQBbeAhgxa9nSQAdEFXJuLmNLFyANHdSo &callback=initMap">
</script>
</body>
</html>

maps markers with input sliders

Let me explain the project a bit. i have a huge list of stores with addresses (longitude and latitude and code client ....).
Now, my problem is, i must be able to filter these markers depending on CodeClient i mean to find the client in google maps based on CodeClient .
The implementation is similar to the answer I mentioned before. You should add an input for code of client and a search button. In the function where you create markers add a property 'code' for each marker marker.code = CodeClient;. When you click search button it executes the filterByCode() function. If you pass empty value it restores all markers.
Have a look at modified code
// necessary variables
var map;
var infoWindow;
var markersData = [];
var markerCluster;
var markerArray = []; //create a global array to store markers
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(32, -6),
zoom: 7,
mapTypeId: 'roadmap',
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
// create MarkerClusterer, markersArray is not populated yet
markerCluster = new MarkerClusterer(map, [], {
imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
// a new Info Window is created
infoWindow = new google.maps.InfoWindow();
// Event that closes the Info Window with a click on the map
google.maps.event.addListener(map, 'click', function() {
infoWindow.close();
});
// Finally displayMarkers() function is called to begin the markers creation
displayMarkers();
}
google.maps.event.addDomListener(window, 'load', initialize);
// This function will iterate over markersData array
// creating markers with createMarker function
function displayMarkers() {
// this variable sets the map bounds according to markers position
var bounds = new google.maps.LatLngBounds();
// for loop traverses markersData array calling createMarker function for each marker
$.get("https://gist.githubusercontent.com/abdelhakimsalama/358669eda44d8d221bf58c629402c40b/raw/bae93c852669a35f0e7053e9f8d068841ddf146a/get_data_google_api", function(response) {
markersData = JSON.parse(response);
for (var i = 0; i < markersData.length; i++) {
var latlng = new google.maps.LatLng(markersData[i].Latitude, markersData[i].Longitude);
var Route = markersData[i].Route;
var Secteur = markersData[i].Secteur;
var Agence = markersData[i].Agence;
var CodeClient = markersData[i].CodeClient;
var PrecisionGPS = markersData[i].PrecisionGPS;
var Latitude = markersData[i].Latitude;
var Longitude = markersData[i].Longitude;
var BarCode = markersData[i].BarCode;
var PrenomClient = markersData[i].PrenomClient;
var NumAdresse = markersData[i].NumAdresse;
var Tel = markersData[i].Tel;
var Whatsapp = markersData[i].Whatsapp;
var NbrFrigo = markersData[i].NbrFrigo;
var OpenAm = markersData[i].OpenAm;
var CloseAm = markersData[i].CloseAm;
var OpenPm = markersData[i].OpenPm;
var ClosePm = markersData[i].ClosePm;
var OpenAmVen = markersData[i].OpenAmVen;
var CloseAmVen = markersData[i].CloseAmVen;
var OpenPmVen = markersData[i].OpenPmVen;
var ClosePmVen = markersData[i].ClosePmVen;
var OpenAmDim = markersData[i].OpenAmDim;
var CloseAmDim = markersData[i].CloseAmDim;
var OpenPmDim = markersData[i].OpenPmDim;
var ClosePmDim = markersData[i].ClosePmDim;
var IMEI = markersData[i].IMEI;
var Date_Added = markersData[i].Date_Added;
createMarker(latlng, Route, Agence, Secteur, CodeClient, PrecisionGPS, Latitude, Longitude, BarCode, PrenomClient, NumAdresse, Tel, Whatsapp, NbrFrigo, OpenAm, CloseAm, OpenPm, ClosePm, OpenAmVen, CloseAmVen, OpenPmVen, ClosePmVen, OpenAmDim, CloseAmDim, OpenPmDim, ClosePmDim, IMEI, Date_Added);
// marker position is added to bounds variable
bounds.extend(latlng);
}
// Finally the bounds variable is used to set the map bounds
// with fitBounds() function
map.fitBounds(bounds);
});
}
// This function creates each marker and it sets their Info Window content
function createMarker(latlng, Route, Agence, Secteur, CodeClient, PrecisionGPS, Latitude, Longitude, BarCode, PrenomClient, NumAdresse, Tel, Whatsapp, NbrFrigo, OpenAm, CloseAm, OpenPm, ClosePm, OpenAmVen, CloseAmVen, OpenPmVen, ClosePmVen, OpenAmDim, CloseAmDim, OpenPmDim, ClosePmDim, IMEI, Date_Added) {
var marker = new google.maps.Marker({
map: map,
position: latlng,
title: CodeClient
});
marker.code = CodeClient;
markerArray.push(marker); //push local var marker into global array
// add marker to the MarkerClusterer
markerCluster.addMarker(marker);
// This event expects a click on a marker
// When this event is fired the Info Window content is created
// and the Info Window is opened.
google.maps.event.addListener(marker, 'click', function() {
var dicoFrigosDetails = {};
var HTMLtext = "";
for (var i = 1; i <= Object.keys(dicoFrigosDetails).length / 4; i++) {
HTMLtext += '';
}
// Creating the content to be inserted in the infowindow
var iwContent = '<div id="iw_container">' +
'<div class="iw_title">Code Client : ' + CodeClient +
'</div>' + '<div class="iw_content">Précision : ' + PrecisionGPS +
'<br />Latitude : ' + Latitude +
'<br />Longitude : ' + Longitude +
'<br />Route : ' + Route +
'<br />Secteur : ' + Secteur +
'<br />Agence : ' + Agence +
'<br />Code-barres : ' + BarCode +
'<br />prenom de Client : ' + PrenomClient +
//'<br />nom Complet de Client : ' + PrenomClient + ' ' + NomClient +
'<br />Num Adresse : ' + NumAdresse +
'<br />Téléphone : ' + Tel +
'<br />Whatsapp : ' + Whatsapp +
'<br />Nbr Frigos : ' + NbrFrigo + HTMLtext +
'<br />Ouverture Matin : ' + OpenAm +
'<br />Fermeture Matin : ' + CloseAm +
'<br />Ouverture après-midi : ' + OpenPm +
'<br />Fermeture Après-midi : ' + ClosePm +
'<br />Ouverture Matin Ven : ' + OpenAmVen +
'<br />Fermeture Matin Ven : ' + CloseAmVen +
'<br />Ouverture après-midi Ven: ' + OpenPmVen +
'<br />Fermeture après-midi Ven: ' + ClosePmVen +
'<br />Ouverture Matin Dim : ' + OpenAmDim +
'<br />Fermeture Matin Dim : ' + CloseAmDim +
'<br />Ouverture après-midi Dim : ' + OpenPmDim +
'<br />Fermeture après-midi Dim : ' + ClosePmDim +
'<br />IMEI : ' + IMEI +
'<br />Date Passage : ' + Date_Added +
'</div>';
// including content to the Info Window.
infoWindow.setContent(iwContent);
// opening the Info Window in the current map and at the current marker location.
infoWindow.open(map, marker);
});
}
function filterByCode() {
var code = document.getElementById("code-client").value;
var bounds = new google.maps.LatLngBounds();
markerCluster.clearMarkers();
if (code) {
markerArray.forEach(function(marker) {
marker.setMap(null);
});
var filtered = markerArray.filter(function(marker) {
return marker.code === code;
});
if (filtered && filtered.length) {
filtered.forEach(function(marker) {
bounds.extend(marker.getPosition());
marker.setMap(map);
});
markerCluster.addMarkers(filtered);
markerCluster.redraw();
map.fitBounds(bounds);
}
} else {
markerArray.forEach(function(marker) {
bounds.extend(marker.getPosition());
marker.setMap(map);
});
markerCluster.addMarkers(markerArray);
markerCluster.redraw();
map.fitBounds(bounds);
}
}
html {
height: 100%;
background: gray;
}
body {
height: 100%;
margin: 0;
padding: 0;
}
#map-canvas {
height: 100%;
}
#iw_container .iw_title {
font-size: 16px;
font-weight: bold;
}
.iw_content {
padding: 15px 15px 15px 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<title>InnoTech - Map - Server</title>
<meta charset="utf-8">
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript" src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script>
<div id="search-code-container">
<input id="code-client" title="Enter code" type="text" placeholder="Enter code (E.g. 511557)" value=""/>
<input id="code-client-btn" type="button" value="Search" onclick="filterByCode()" />
</div>
<div id="map-canvas" />
I hope this helps!

How to change position of Google Maps infoWindow

As the title says, how can I change the position of an infoWindow like in the image above?
I've followed the instructions from Google. Now I want to change the infowindows position but can't figure out what to do.
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882, 131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var contentString = '<div id="content">' +
'<div id="siteNotice">' +
'</div>' +
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>' +
'<div id="bodyContent">' +
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the ' +
'Northern Territory, central Australia. It lies 335 km (208 mi) ' +
'south west of the nearest large town, Alice Springs; 450 km ' +
'(280 mi) by road. Kata Tjuta and Uluru are the two major ' +
'features of the Uluru - Kata Tjuta National Park. Uluru is ' +
'sacred to the Pitjantjatjara and Yankunytjatjara, the ' +
'Aboriginal people of the area. It has many springs, waterholes, ' +
'rock caves and ancient paintings. Uluru is listed as a World ' +
'Heritage Site.</p>' +
'<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">' +
'https://en.wikipedia.org/w/index.php?title=Uluru</a> ' +
'(last visited June 22, 2009).</p>' +
'</div>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Uluru (Ayers Rock)'
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
You can use the pixelOffset property.
var infowindow = new google.maps.InfoWindow({
pixelOffset: new google.maps.Size(200,0)
});
See https://developers.google.com/maps/documentation/javascript/reference#InfoWindowOptions
Working code snippet:
function initialize() {
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(0, 0),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(0, 0),
map: map,
});
var infowindow = new google.maps.InfoWindow({
content: 'Hello world',
pixelOffset: new google.maps.Size(200, 0)
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
initialize();
#map-canvas {
height: 180px;
}
<div id="map-canvas"></div>
<script src="//maps.googleapis.com/maps/api/js?key= AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>

Google maps api v3 infowindow not showing on click

I cant seem to get it working. I used this on several other websites but with this new one it wont show my infowindow (infobox).
Markers are in position and when you are on a marker he is showing the title.
I can post the code but it comes with a lot of php and is a bit of a mess.
This is the url:
http://intertyre.server170.nognietactief.nl/montagepunten
I use the exact same sript on:
http://www.tyfoonbanden.nl/tyfoon-dealers
Working perfect.
Dont know why this is happening so if there is someone that knows what is causing the problem. Please share because I really dont know.
Thanks in advance.
The code (I know it is a mess, have to
<script type="text/javascript">
var geocoder;
var map;
var side_bar_html = "";
var gmarkers = [];
var infobox;
function initialize() {
// Create an array of styles.
var blueOceanStyles = [
{
featureType: "all",
elementType: "all",
stylers: [
{ saturation: -100 } // <-- THIS
]
}
];
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: <?php
if(is_array($postcodevelden) && count($postcodevelden) > 0 && !empty($_POST['address']))
{
switch($radius)
{
case "5":
echo "12";
break;
case "10":
echo "11";
break;
case "15":
case "20":
echo "10";
break;
case "30":
case "40":
echo "9";
break;
}
}else{
echo "7";
}
?>,
center: new google.maps.LatLng(<?php if(is_array($postcodevelden) && count($postcodevelden) > 0) { echo $lat.", ".$lon; } else { echo "52.2008737173322, 5.25146484375"; } ?>),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
map.setOptions({styles: blueOceanStyles});
<?php
if(is_array($adressen) AND count($adressen) > 0)
{
foreach($adressen as $adres)
{
$afstand = round((6371 * acos(sin(deg2rad($lat)) * sin(deg2rad($adres->locatie_lat)) + cos(deg2rad($lat)) * cos(deg2rad($adres->locatie_lat)) * cos(deg2rad($adres->locatie_lon) - (deg2rad($lon))))), 2);
?>
addMarker(<?php echo $adres->locatie_lat.", ".$adres->locatie_lon.", '".$adres->locatie_naam."', '".$adres->locatie_straat."', '".$adres->locatie_postcode."', '".$adres->locatie_plaats."', '".$adres->locatie_telefoon."', '".$adres->locatie_website."', '".$afstand."'"; ?>);
<?php
}
}
?>
document.getElementById("table_markers").innerHTML = side_bar_html;
}
function myclick(i) {
map.setCenter(gmarkers[i].getPosition());
google.maps.event.trigger(gmarkers[i], "click");
}
var infowindow = new google.maps.InfoWindow({
content: document.getElementById("infobox"),
disableAutoPan: false,
maxWidth: 250,
pixelOffset: new google.maps.Size(0, 0),
zIndex: null,
boxStyle: {
background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/tipbox.gif') no-repeat",
opacity: 0.95,
width: "280px"
},
closeBoxMargin: "12px 4px 2px 2px",
closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
infoBoxClearance: new google.maps.Size(1, 1)
});
function addMarker(lat, lon, naam, straat, postcode, plaats, telefoon, website, afstand)
{
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
map: map,
icon: "/wp-content/uploads/wheel-icon.png",
title: naam
});
google.maps.event.addListener(marker, 'click', function() {
var contentString = '<div id="infobox">'+
'<b style="border-bottom: 1px solid #000000; color:#00377b;">' + naam + '</b><br/>'+
straat + '<br/>' +
postcode + ' ' + plaats + '<br/>';
if(telefoon != "")
{
contentString = contentString + telefoon + '<br/>';
}
if(website != "")
{
contentString = contentString + 'Website: <u><a target="_blank" rel="nofollow" href="http://' + website + '">' + website + '</a></u>';
}
contentString = contentString + '</div>';
infowindow.setContent(contentString);
infowindow.open(map, marker);
});
gmarkers.push(marker);
side_bar_html += '<table id="marker_list"><tr>'+ '<td onclick="javascript:myclick(' + (gmarkers.length-1) + ')"><a><h3>' + naam + '</h3>' + straat + '<br/>' + postcode + ' ' + plaats + '<br/>' + telefoon + '<br/>' + website + '<br/>' + '<u>Afstand ' + afstand + ' km</u>' +'</td>' +'<\/a></tr></table><br>';
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<form action="/montagepunten" method="POST">
<input id="address" name="address" type="textbox"<?php if(isset($_POST['zoekpost']) && $_POST['zoekpost'] == 'zoek') { echo " value=\"".$_POST['address']."\""; } ?> style="float:left; height:30px; margin-right:10px; width:100px;"><select name="afstand" style="display:none;">
<option selected="selected" value="10">10 km</option>
</select>
<input type="submit" name="zoekpost" id="zoekpost" value="zoek">
</form>
<br/>
<br/>
<div class="mapborder">
<div class="map-width">
<div id="map_canvas"></div>
</div>
<div class="one_third-last" style="overflow-y:auto; overflow-x:hidden; height:579px; width:100%; clear:left; padding-top:0px; padding-bottom:0px; margin-top:20px;"><div id="table_markers"></div></div>
</div>
Problem solved...
Nothing wrong with the code but there was a conflict with loading google maps api multiple times.
Using Avada as Theme for website. For other users that run into this:
WP Dashboard > Appearance > Theme Options > Extra options page.
There you can disable the Google Maps Api for Avada and error is gone.