We're using Google Maps API to display a map, which is working fine.
I see lots of complaints where the marker on people's maps isn't in the center.
We actually want the opposite, due to the location of the premises on this particular map we'd like to have the map slightly off-center with the location and its marker towards the top-right corner of the map (to clarify, we want to essentially shift the map canvas, not change the actual location of the premises).
Below is the code we're using. The center: latlng
is what centers the map, so I know we need to change the center
parameter to something else, but I'm not sure what.
<script src="//maps.google.com/maps/api/js?sensor=false&region=GB"></script>
<script>
var geocoder1 = new google.maps.Geocoder;
geocoder1.geocode( { 'address': "360 Any Street, 12345"}, function(results, status) {
myGeocode(results, status, 'map_canvas');
});
function myGeocode(results, status, canvas) {
if (status == google.maps.GeocoderStatus.OK) {
var latlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
var myOptions = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
var map = new google.maps.Map(document.getElementById(canvas), myOptions);
var myMarker = new google.maps.Marker({ position: latlng, map: map });
} else {
// alert("Geocode was not successful for the following reason: " + status);
}
}
</script>
<div id="map_canvas" style="width: 600px; height: 600px;"></div>