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>
Related
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>
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Hi i have been using this code to show multiple location on a google map and also dropping pins on each location.
var mylocation = new google.maps.LatLng(52.520816, 13.410186);
var neighborhoods = [
new google.maps.LatLng(52.511467, 13.447179),
new google.maps.LatLng(52.549061, 13.422975),
new google.maps.LatLng(52.497622, 13.396110),
new google.maps.LatLng(52.517683, 13.394393)
];
var markers = [];
var map;
function initialize() {
var mapOptions = {
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: mylocation
};
map = new google.maps.Map(document.getElementById('googleMap'),
mapOptions);
drop();
}
function drop(){
for (var i = 0; i < neighborhoods.length; i++)
{
markers.push(new google.maps.Marker({
position: neighborhoods[i],
map: map,
}));
}
}
what i want is to show info window on all the pins showing their respective lats and lngs
Thanks
function drop()
{
for (var i = 0; i < neighborhoods.length; i++)
{
var marker= new google.maps.Marker({
position: neighborhoods[i],
map: map,
});
var infoWindow = new google.maps.InfoWindow({content:marker.getPosition()});
infoWindow.open(map, marker);
}
}
All the information you need is in the Google maps documentation, in the InfoWindow section, where they show this example:
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h2 id="firstHeading" class="firstHeading">Uluru</h2>'+
'<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="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'http://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);
});
I'm going to have several markers (right now I'm just doing two until I get the structure going) and I'd like to be able to click on external links that open the marker's info box, but when one marker's info box is open the other gets closed. I'd also like to be able to hide and show the markers. So when one button is pushed it hides the first marker, and when the other button is pushed it shows the first one and hides the second.
Right now I have my map set up like this and am unsure where to go from here with how to toggle the visibility setting and the info bubbles.
var LOC_850 = new google.maps.LatLng(42.326435,-71.149499);
var mapOptions = {
zoom: 16,
center: LOC_850,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var CONTENT_850 = '<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 '+
'Heritage Site.</p>'+
'</div>';
var INFO_850 = new google.maps.InfoWindow({
content: CONTENT_850
});
var BTN_850 = 'CONTAINER_850';
var MARKER_850 = new google.maps.Marker({
position: LOC_850,
map: map,
title: 'Hello World!'
});
google.maps.event.addListener(MARKER_850, 'click', function() {
INFO_850.open(map,MARKER_850);
});
google.maps.event.addDomListener(document.getElementById(BTN_850), 'click', function() {
INFO_850.open(map,MARKER_850);
});
var LOC_850_60bus_out = new google.maps.LatLng(42.326822,-71.150157);
var CONTENT_850_60bus_out = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">DIFFERENT</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 '+
'Heritage Site.</p>'+
'</div>';
var INFO_850_60bus_out = new google.maps.InfoWindow({
content: CONTENT_850_60bus_out
});
var BTN_850_60bus_out = 'CONTAINER_850_60bus_out';
var MARKER_850_60bus_out = new google.maps.Marker({
position: LOC_850_60bus_out,
map: map,
title: 'Hello World!'
});
google.maps.event.addListener(MARKER_850_60bus_out, 'click', function() {
INFO_850_60bus_out.open(map,MARKER_850_60bus_out);
});
google.maps.event.addDomListener(document.getElementById(BTN_850_60bus_out), 'click',
function() {
INFO_850_60bus_out.open(map,MARKER_850_60bus_out);
});
}
function loadScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&' +
'callback=initialize';
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
See [this example "categories" map(http://www.geocodezip.com/v3_MW_example_categories.html) (translated from Mike Williams' v2 tutorial example
I has
(what I call) v2 infowindow functionality (single infowindow)
checkboxes that hide/show categories of markers.
I am try the Google Maps API and run into a little problem. Look at this example below. I want to have a Infobox open when I go to the site (not like in this example from google that it is cloesed and triggered by an click event). How to manage this? Maybe this is a beginners question to a Google Maps Api pro^^
> function initialize() {
> var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
> var myOptions = {
> zoom: 4,
> center: myLatlng,
> mapTypeId: google.maps.MapTypeId.ROADMAP
> }
>
> var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
>
> var contentString = '<div id="content">'+
> '<div id="siteNotice">'+
'hello world</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);
> }); }
Just add infowindow.open(map,marker); to the end of your initialize() function:
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
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="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'http://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);
});
infowindow.open(map,marker);
}
I'm trying to add a Google map to a website I am developing.
I have managed to include the map, with the correct long & lat coordinates (Using V3 of the API), but I'm having trouble adding a tooltip like you see when clicking a marker
See this URL for details
http://maps.google.co.uk/maps?q=york+web+design&oe=utf-8&rls=org.mozilla:en-GB:official&client=firefox-a&um=1&ie=UTF-8&hl=en&sa=N&tab=wl
When one of those markers is clicked, the tooltip appears, how can I achieve the same result on my small map?
The marker click items are called InfoWindows (google.maps.InfoWindow).
I used the api page for reference when I built our maps, it was really helpful and easy to understand.
http://code.google.com/apis/maps/documentation/javascript/overlays.html#InfoWindows
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
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="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'http://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);
});