I am completely new to Google Maps and just creating my first map so that I can include it in my site.
I am trying to limit the area in which the user can only move to the UK, and looked at a few posts here that all give very similar answers, however I could not get the code to work for me.This solution is the closest that I have , but whenever I try to move a map, it focuses on one of my boundary points and I can’t move it anywhere,
Perhaps I made a really stupid mistake, and in this case I apologize, but I can not understand what is wrong. Does anyone have any ideas?
thank
My code is below (taken from a sample Google code and then added) - the border part is at the bottom, starting with setting borders for the UK:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>Google Maps</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=MYKEY&sensor=false">
</script>
<?
$apikey = MYKEY;
$geourl = "http://maps.google.com/maps/geo?q=LS255AA&output=csv&key=$apikey";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $geourl);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$csvContent = trim(curl_exec($c));
curl_close($c);
list($httpcode, $elev, $lat, $long) = split(",", $csvContent);
?>
<script type="text/javascript">
var lat = "<?= $lat ?>";
var long = "<?= $long ?>";
</script>
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(lat, long);
var myOptions = {
center: myLatlng,
zoom: 9,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mymap = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var opt = { minZoom: 7, maxZoom: 11 };
mymap.setOptions(opt);
var marker = new google.maps.Marker({
position: myLatlng,
map: mymap,
title:"Hello World!"
});
var contentString = '<h2>I am an info window</h2>'+'<p>Hello my name is infowindow, I need more text to test how big I get</p>';
var infowindow = new google.maps.InfoWindow({
content: contentString,
});
infowindow.setOptions({maxWidth:200});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(mymap,marker);
});
var strictBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(60.88770, -0.83496),
new google.maps.LatLng(49.90878, -7.69042)
);
google.maps.event.addListener(mymap, 'dragend', function() {
if (strictBounds.contains(mymap.getCenter())) return;
var c = mymap.getCenter(),
x = c.lng(),
y = c.lat(),
maxX = strictBounds.getNorthEast().lng(),
maxY = strictBounds.getNorthEast().lat(),
minX = strictBounds.getSouthWest().lng(),
minY = strictBounds.getSouthWest().lat();
if (x < minX) x = minX;
if (x > maxX) x = maxX;
if (y < minY) y = minY;
if (y > maxY) y = maxY;
mymap.setCenter(new google.maps.LatLng(y, x));
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:50%; height:50%"></div>
</body>
</html>