ddantes
asked on
Configuring a Google Map
I'm trying to learn how to configure a Google Map API V3, and having some challenges. I would like to be able to specify coordinates for the initial view of the map, which differ from coordinates of the marker. I'd like the zoom control to zoom in on the marker, not on the initial coordinates of the map. Can you edit the following code to achieve that?
<script>
jQuery(document).ready(function () {
initmap("20.915927","-156.282931","Maui Tradewinds","4320 Une Place, Haiku","Hawaii")
})
function initmap(lat,lng,hname,add,city) {
var secheltLoc = new google.maps.LatLng(lat,lng);
var myMapOptions = {
zoom: 14
,center: secheltLoc
,mapTypeId: google.maps.MapTypeId.ROADMAP,disableDefaultUI: true,
draggable: false, zoomControl: false, scrollwheel: false, disableDoubleClickZoom: true
};
var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
var contentString =hname+"<br>" +add+"<br>"+city //Style here as you like
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
map: theMap
});
// Show the popup on load.
google.maps.event.addListenerOnce(theMap, 'idle', function() {
infowindow.open(theMap,marker);
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(theMap,marker);
});
}
</script>
ASKER
Thank you. I'll try this, but I was hoping the initial map center could be set with a different initial (lat, long) instead of panning by pixels. If I use pixels, won't the result vary with the screen size and resolution of the user's device?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is exactly what I hoped for.
theMap.panBy(0, -100);
Then you can add an event listener to re-center the map to the marker location on zoom_changed. Of course you will have to enable the zoom control.
google.maps.event.addListe
theMap.setCenter(secheltLo
});