[Google Maps API v2] How to load points in bounds only
Hello,
I am trying to build a map that loads points only within the bounds of
the map being shown. This does not have to be dynamic loading, just
points within the current bounds. I have tried a few ways but without
luck. I can get points to load by this method, but when I tried doing
it within bounds it stopped working.
Here is the code for my map:
<script src="http://maps.google.com/maps?
file=api&v=3&sensor=false&key=ABQIAAAAYtlRX2_tsErRxmwyuiJQHBTr_WrersKvCQA1ElrhOnBL_vAL2hRUPr-
lOPZffcpr5Opjeuh970S3DQ" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng((lat) ,(lng)), 11);
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var nelng = northEast.lng();
var nelat = northEast.lat();
var swlng = southWest.lng();
var swlat = southWest.lat();
var stuff = 'phpsqlajax_genxml2.php?';
var stuff2 = 'nelang='+ nelng +'&nelat='+ nelat + '&swlng=' + swlng
+ '&swlat=' + swlat;
var stuff3 = stuff + stuff2
GDownloadUrl(stuff3, function(data) {
var xml = GXml.parse(data);
var markers =
xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var callsign = markers[i].getAttribute("callsign");
var point = new
GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var marker = createMarker(point, callsign);
map.addOverlay(marker);
}
});
}
}
function createMarker(point, callsign) {
var marker = new GMarker(point);
var html = "<a href='./info.php?call=" + callsign + "'><b>" +
callsign + "</b></a> <br/>" + "Click for more info";
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
//]]>
</script>
This is calling upon phpsqlajax_genxml2.php to find the points desired
in the database (SQL) and load them as an xml file which can be used.
This method for loading points has worked great when loading all
points. As you can see I have tried using passing data via the call
url but that seems not to be working. Here is the code for
thephpsqlajax file: (***** are only there to remove secure data)
<?php
include "********server*******info.php";
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
$nelng = $_GET['nelng'];
$nelat = $_GET['nelat'];
$swlng = $_GET['swlng'];
$swlat = $_GET['swlat'];
// Opens a connection to a mySQL server
mysql_connect("$******","$******","$******")or die("ERROR Can Not
Connect to Server");
// Set the active mySQL database
mysql_select_db("$*******")or die("Database Unaccessable");
// Select all the rows in the markers table
$query = "SELECT * FROM `******` WHERE `lat` BETWEEN ".$swlat." AND ".
$nelat." AND `lng` BETWEEN ".$nelng." AND ".$swlng." LIMIT 0, 100";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while($row = mysql_fetch_array($result)){
$callsign = $row[0];
$lat = $row[2];
$long = $row[3];
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'callsign="';
echo $callsign.'" ';
echo 'lat="';
echo $lat.'" ';
echo 'lng="';
echo $long.'" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>
Thanks in advance,
Tim R
--
You received this message because you are subscribed to the Google Groups "Google Maps API V2" group.
To post to this group, send email to google-maps-api@googlegroups.com.
To unsubscribe from this group, send email to google-maps-api+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home