lvmllc
asked on
GLatLngBounds( ) to zoom to extent of 2 points via Google Maps API
I am trying to create a map using hte Google API that will automatically zoom to best fit two points that are provided by the user. These points are contained in a PHP variable and I have transfered them to a javascript array.
Initially I had planned to use
I keep getting this error
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C)
Timestamp: Thu, 11 Nov 2010 15:18:50 UTC
Message: Invalid argument.
Line: 395
Char: 18
Code: 0
URI: http://maps.gstatic.com/intl/en_us/mapfiles/285c/maps2.api/main.js
Initially I had planned to use
latlngbounds.extend(latlng[i]);
to extend the GLatLngBounds but it did not work, nor did var point = new GLatLng(latlng[i]); latlngbounds.extend(point);
I keep getting this error
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C)
Timestamp: Thu, 11 Nov 2010 15:18:50 UTC
Message: Invalid argument.
Line: 395
Char: 18
Code: 0
URI: http://maps.gstatic.com/intl/en_us/mapfiles/285c/maps2.api/main.js
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zoom to extents</title>
<link href="../css/layout.css" rel="stylesheet" type="text/css" />
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAu6sjqcmGfoqTHmTvfkq0ChSpkSOrz0Cwg3N68il0aaFJTpnuCBQxjGoicyV8T8a1Pm6s99H3kAGuoA" type="text/javascript"></script>
<?php
$coord1="47.6, -100.89";
$coord2="47.55, -100.88";
?>
<script language="Javascript" type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("mapPane_gmap"));
//map.setCenter(new GLatLng(0,0),0);
var latlng= new Array();
latlng[0] = "<?php echo $coord1;?>";
latlng[1] = "<?php echo $coord2;?>";
var latlngbounds = new GLatLngBounds( );
for ( var i = 0; i < latlng.length; i++ ){
alert(latlng[i]);
//latlngbounds.extend(latlng[i]);
var point = new GLatLng(latlng[i]);
latlngbounds.extend(point);
}
map.setCenter( latlngbounds.getCenter( ), map.getBoundsZoomLevel( latlngbounds ) );
//map.setCenter(new GLatLng(47.6, -100.89), 13);
var customUI = map.getDefaultUI();
customUI.controls.scalecontrol = false;
customUI.controls.menumaptypecontrol = true;
map.setUI(customUI);
}
}
</script>
</head>
<body onload="initialize()">
<div id="mapPane_gmap" style="height:400px; width:700px; margin-left: 0px;">
</div>
</body>
<HEAD>
</HEAD>
</html>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Worked great. I just put the following in and I was good to go
var latlng = [
new google.maps.LatLng( <?php echo $coord1;?> ),
new google.maps.LatLng( <?php echo $coord2;?> )
];
var latlng = [
new google.maps.LatLng( <?php echo $coord1;?> ),
new google.maps.LatLng( <?php echo $coord2;?> )
];
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_3350-Using-the-Google-Maps-API-in-PHP.html