I have plotted over a thousand markers on a map from a mysql database. This page map.php takes an xml and grabs the information. Within this array, several points have multiple entries in the database, but google maps only shows the infowindow for the most recent marker plotted.
I'd like the infowindow to list all for that locations, similar to how a loop would work in php. So everything that shares a lat and a long would be within the one info window
The code i use:
downloadUrl("map/map_data_source.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var date = markers[i].getAttribute("date");
var artist = markers[i].getAttribute("artist");
var venue = markers[i].getAttribute("venue");
var address = markers[i].getAttribute("address");
var city = markers[i].getAttribute("city");
var idgigs = markers[i].getAttribute("id");
var country = markers[i].getAttribute("country");
var count = markers[i].getAttribute("count");
var swith = markers[i].getAttribute("swith");
var stage = markers[i].getAttribute("stage");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html =
'<div id="infoWindow" width="600px"><img src="projects/components/' + artist + '">' +
'<br><br>' + date +
'<br><b>' + venue + '</b> / ' + city + '<br>' + swith + stage +
'<br><b><a class="second_sub_menu" href="../projects/bands.php?sub=Setlist&info=' + artist + '&id=' + idgigs + '">SHOW INFORMATION</a></b>';
var marker = new google.maps.Marker({
map: map,
position: point,
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + count + '|' + type + '|000000',
zIndex: i
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
if (map.getZoom() < 4) map.setCenter(marker.getPosition());
if (map.getZoom() < 4) map.setZoom(4);
});
google.maps.event.addListener(map, "click", function() {infoWindow.close();});
}
So this question has appeared a million and one times, but there still appears to be no real answer.. (There are mentions to markclusters and spiderers as another way of showing these results, but I want the markers how they are)..
Thank you mucho in advance, I have progressed well, but without this bit working, the project may as well be binned..! :(
Using #Dr.Molle link i got it working, in case anyone is after this feature, this is my new code
var markerContents={};
var infoWindow = new google.maps.InfoWindow;
downloadUrl("map/map_data_source.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var date = markers[i].getAttribute("date");
var artist = markers[i].getAttribute("artist");
var venue = markers[i].getAttribute("venue");
var address = markers[i].getAttribute("address");
var city = markers[i].getAttribute("city");
var idgigs = markers[i].getAttribute("id");
var country = markers[i].getAttribute("country");
var count = markers[i].getAttribute("count");
var swith = markers[i].getAttribute("swith");
var stage = markers[i].getAttribute("stage");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var customIcons = {
FFFFFF: {
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + count + '|' + type + '|000000'
},
upcoming: {
icon: '../map/marker/orange.png'
}
};
var markerId = point.toString();
if(!markerContents[markerId]){
markerContents[markerId] = [];
}
var html =
'<div id="infoWindow" width="600px"><img src="projects/components/' + artist + '">' +
'<br><br>' + date +
'<br><b>' + venue + '</b> / ' + city + '<br>' + swith + stage +
'<br><b><a class="second_sub_menu" href="../projects/bands.php?sub=Setlist&info=' + artist + '&id=' + idgigs + '">SHOW INFORMATION</a></b>';
var icon = customIcons[type] || {};
markerContents[markerId].push(html);
var marker = new google.maps.Marker({
map: map,
position: point,
zIndex: i,
icon: icon.icon
});
bindInfoWindow(marker, map, infoWindow, markerContents[markerId]);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html.join('<hr/>'));
infoWindow.open(map, marker);
if (map.getZoom() < 4) map.setCenter(marker.getPosition());
if (map.getZoom() < 4) map.setZoom(4);
});
google.maps.event.addListener(map, "click", function() {infoWindow.close();});
}
Because i wanted custom icons and I wanted a select group of markers to always be at the top, i had to modify the icons code too, but it works. So thank you to those that helped
Related
I am using the following script to show maps in my application. there are some issues coming :
it's displaying only 10 places.
it showing provided a place in wrong place.
when I want to see only one place then background roadmap is not coming.
I want to display on India map but it's not coming.
Please help me out with this issues.
var graphVal = Kavitha, Ahmedabad, Gujarat##Chavand, Amreli, Gujarat##Khadol, Anand, Gujarat##Ramgadhi, Arvalli, Gujarat##Vagharol, Banas kantha, Gujarat##Matar, Bharuch , Gujarat##Patana, Bhavnagar, Gujarat##Dhasa Vishi, Botad , Gujarat##Panchwada, Dahod, Gujarat##Pimpari, Dang, Gujarat##Rajpar, Devbhumi Dwarka , Gujarat##Harmadiya
, Gir Somnath , Gujarat##Jamvanathali;
var mapid = 'map';
var zoomNo = 15;
graphVal = graphVal.replace(/##\s*$/, "");
var graphvalue = graphVal.split('##');
var ccont = graphvalue.length;
var locations = [];
var geocoder = new google.maps.Geocoder();
var address = '';
var addresArr = [];
for (var i = 0; i < ccont; i++) {
var k = 1;
address = graphvalue[i].replace('SDH', 'Sub District Hospital');
address = address.replace('DH', 'District Hospital');
address = address.replace('-', ' ');
// address = graphvalue[i];
addresArr[i+1] = graphvalue[i];
geocoder.geocode( { 'address': address}, function(results, status) {
// console.log(results[0]);
var tempArray = [];
if (status == google.maps.GeocoderStatus.OK)
{
var Latitudee = results[0].geometry.location.lat();
var Longitudee = results[0].geometry.location.lng();
tempArray.push(addresArr[k]);
tempArray.push(Latitudee);
tempArray.push(Longitudee);
tempArray.push(k);
k++;
}
if (typeof tempArray !== 'undefined' && tempArray.length > 0) {
locations.push(tempArray);
}
});
}
setTimeout(
function()
{
fillMap(locations,mapid,zoomNo);
}, 1000);
function fillMap(locations,mapid,zoomNo){
// Setup the different icons and shadows
var iconURLPrefix = 'http://maps.google.com/mapfiles/ms/icons/';
var icons = [
iconURLPrefix + 'red-dot.png',
iconURLPrefix + 'green-dot.png',
iconURLPrefix + 'blue-dot.png',
iconURLPrefix + 'orange-dot.png',
iconURLPrefix + 'purple-dot.png',
iconURLPrefix + 'pink-dot.png',
iconURLPrefix + 'yellow-dot.png'
]
var iconsLength = icons.length;
var map = new google.maps.Map(document.getElementById(mapid), {
zoom: zoomNo,
//scrollwheel: false,
// center: new google.maps.LatLng(28.6139, 77.2090),
// mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM
}
});
var infowindow = new google.maps.InfoWindow({
maxWidth: 160
});
var markers = new Array();
var iconCounter = 0;
// Add the markers and infowindows to the map
for (var i = 0; i < locations.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: icons[iconCounter]
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
iconCounter++;
// We only have a limited number of possible icon colors, so we may have to restart the counter
if(iconCounter >= iconsLength) {
iconCounter = 0;
}
}
autoCenter(markers,map);
}
function autoCenter(markers,map) {
// Create a new viewpoint bound
var bounds = new google.maps.LatLngBounds();
// Go through each...
for (var i = 0; i < markers.length; i++) {
bounds.extend(markers[i].position);
}
// Fit these bounds to the map
map.fitBounds(bounds);
}
Thanks & Regards,
Asjad
Edit:
I'm trying over the last couple of weeks to solve my problem. As I'm a True Beginner I'm learning the Code during the work Progress... I will try to clarify my question which hopefully show me the answer.
As i was asking before : I'm developing a web App based on Google maps API 3. A GPS-Logger is feeding a table on Mysql server with those values: id, latitude, longitude, date, time, userid. I want to create multiple unique Polylines. For each date group a new Polyline.
As I was saying, I've made some progress but I'm not quite sure that I'm on the right track.
Now I'm not sure what I'm getting it ether few Polylines that are connected making them into a big Polyline or Few Polylines on top of each others...
Another problem ist that with this code I can't seem to show the first "date-group Polyline".
I've Posted the Newer code Below the Original one and a >>jsfiddle<< link (although I didn't managed to get jsfiddle working on my side).
I assuming that this is no longer a Google-Maps question but I would be thankful if someone can help me to solve and understand it.
This is the code part I've posted before:
var map = new google.maps.Map(document.getElementById('map'), myOptions);
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("output-xml.php", function(data)
{
var points=[];
var markerbgn=[];
var markerend=[];
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++)
{
var date = markers[i].getAttribute("date");
var time = markers[i].getAttribute("time");
var timebgn = markers[0].getAttribute("time");
var timeend = markers[markers.length-1].getAttribute("time");
var type = markers[i].getAttribute("usid");
points[i] = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html1 = "<b>" + date + "</b> <br/>" + timebgn + "</b> <br/>" + "Start Point";
var html2 = "<b>" + date + "</b> <br/>" + timeend + "</b> <br/>" + "End Point";
var content2 = "<b>" + "User: " + type + "</b> <br/>" + date + "</b> <br/>" + "User Route";
var encoded_path = google.maps.geometry.encoding.encodePath(points);
console.log(encoded_path);
}
var decoded_path = google.maps.geometry.encoding.decodePath(encoded_path);
// Polyline
var polyOptions = {
path: decoded_path,
map: map,
clickable: true,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
}
//line text
var info = decoded_path;
// Polyline
var polyline = new google.maps.Polyline(polyOptions);
polyline.setMap(map);
createInfoWindow(polyline, map, infoWindow, content2);
This is the Newer Code:
var map = new google.maps.Map(document.getElementById('map'), myOptions);
var infoWindow = new google.maps.InfoWindow();
// Change this depending on the name of your PHP file
downloadUrl("output-xml.php", function(data) {
var markerbgn=[];
var markerend=[];
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
var routeNum = [];
var mPoints =[];
for (var i = 0; i < markers.length-1; i++) {
var date = markers[i].getAttribute("date").split("-").join("");
var dateAdv = markers[i+1].getAttribute("date").split("-").join("");
var datePrv = [];
var dateEnd = markers[markers.length-1].getAttribute("date").split("-").join("");
var time = markers[i].getAttribute("time");
var timebgn = markers[0].getAttribute("time");
var timeend = markers[markers.length-1].getAttribute("time");
var type = markers[i].getAttribute("usid");
var routesCng=[];
var points=[];
if (dateAdv != date){
if (!routesCng) routesCng=[];
routesCng = i;
routeNum++;
for (var k = 0; k < markers.length; k++) {
points.push(new google.maps.LatLng(
parseFloat(markers[k].getAttribute("lat")),
parseFloat(markers[k].getAttribute("lng"))));
}
setPoints();
setPolyline();
}
//alert([datePrv,time,dateAdv]); //**********************************
var html1 = "<b>" + date + "</b> <br/>" + timebgn + "</b> <br/>" + "Start Point";
var html2 = "<b>" + date + "</b> <br/>" + timeend + "</b> <br/>" + "End Point";
var content2 = "<b>" + type + "</b> <br/>" + dateAdv + "</b> <br/>" + "User Route";
}
function setPoints() {
mPoints = points.splice([routesCng]);
//alert([date,routesCng,dateAdv,routeNum]);
}
function setPolyline() {
alert([date,routesCng,dateAdv,routeNum,mPoints]);
var encoded_path = google.maps.geometry.encoding.encodePath(mPoints);
console.log(encoded_path);
var decoded_path = google.maps.geometry.encoding.decodePath(encoded_path);
var polyOptions = {
path: decoded_path,
map: map,
clickable: true,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
}
// Polyline
var polyline = new google.maps.Polyline(polyOptions);
//line text
var info = decoded_path;
polyline.setMap(map);
createInfoWindow(polyline, map, infoWindow, content2);
if(decoded_path.length!=0){
markerbgn = new google.maps.Marker({
map: map,
position: decoded_path[0],
draggable: false,
visible: true
});
markerend = new google.maps.Marker({
map: map,
position: decoded_path[decoded_path.length-1],
draggable: false,
visible: true
});
bindInfoWindow(markerbgn, map, infoWindow, html1);
bindInfoWindow(markerend, map, infoWindow, html2);
}
}
});
any help would be greatly appreciated!
I'm not sure why you want to do this in the client, but one way to do it would be to create an array of points for each date:
if (!points[date]) points[date] = [];
points[date].push(new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng"))));
then create your unique polylines from each of those arrays.
load function
function load() {
var cluster = [];
infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(10.6145, -24.3418),
zoom: 2,
mapTypeId: 'roadmap'
});
// Read the data from example.xml
downloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var link = markers[i].getAttribute("link");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + '<a href="' + link + '" >' + markers[i].getAttribute("name") + '</a>' + "</b> <br/>" + "</b> <br/>" + '<a href="' + link + '" >' + markers[i].getAttribute("address") + '</a>';
var icon = customIcons[type] || {};
// create the marker
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
addMarker(marker, html);
cluster.push(marker);
}
var mc = new MarkerClusterer(map,cluster);
//markerCluster = new MarkerClusterer(map, gmarkers);
});
}
add markers
function addMarker(marker, content)
{
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(content);
infoWindow.open(map, marker);
infoWindow.close();
});
}
code for ajax
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
If you click the cluster marker, a "clusterclick" event is fired.
Add an event listener an then close the infowindow:
var mc = new MarkerClusterer(map, cluster);
google.maps.event.addListener(mc, 'clusterclick', function() {
infoWindow.close();
});
I started with https://developers.google.com/maps/articles/phpsqlajax_v3 and am using
https://developers.google.com/maps/articles/phpsqlsearch_v3 to try to dynamically filter the content from a mysql DB and update my markers based on the returned results.
My php returns a valid xml file so no worries there. I'm just not sure what I'm doing wrong for the clearing and creating the new markers from the new query.
The load() function gives me a nice new map with markers on it, but the form doesn't seem to do anything. I even tried just have the form button call clearLocations() and nothing happens. The screen kinda blinks but all the points stay there.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Property Sales</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var markersArr = [];
var map;
var infoWindow;
function updateMap(){
var maxbid = document.getElementById('maxbid').value;
var minbid = document.getElementById('minbid').value;
var salestatus = document.getElementById('salestatus').value;
var saledate = document.getElementById('saledate').value;
infoWindow = new google.maps.InfoWindow;
var queryString = "phpsqlajax_genxml3dynamic.php?maxbid=" + maxbid + "&minbid=" + minbid + "&salestatus=" + salestatus + "&saledate=" + saledate;
//var queryString = "phpsqlajax_genxml3dynamic.php?maxbid=" + maxbid + "&minbid=" + minbid;
queryString="phpsqlajax_genxml3dynamic.php?maxbid=340000&minbid=0&salestatus=*&saledate=*";
downloadUrl( queryString, function(data) {
var xml = data.responseXML;
markers = xml.documentElement.getElementsByTagName("marker");
clearLocations();
for (var i = 0; i < markers.length; i++) {
var SaleDate = markers[i].getAttribute("SaleDate");
var CaseNumber = markers[i].getAttribute("CaseNumber");
var Address = markers[i].getAttribute("Address");
var ZipCode = markers[i].getAttribute("ZipCode");
var Plaintiff = markers[i].getAttribute("Plaintiff");
var Defendant = markers[i].getAttribute("Defendant");
var Attorney = markers[i].getAttribute("Attorney");
var SoldTo = markers[i].getAttribute("SoldTo");
var PID = markers[i].getAttribute("PID");
var Appraisal = markers[i].getAttribute("Appraisal");
var MinBid = markers[i].getAttribute("MinBid");
var SaleAmt = markers[i].getAttribute("SaleAmt");
var SaleStatus = markers[i].getAttribute("SaleStatus");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("Latitude")),
parseFloat(markers[i].getAttribute("Longitude"))
);
var info = "<b>Sale Date:" + SaleDate +"<br/>Address:"+ Address+"<br/>Sale Amount:" + SaleAmt + "</b> <br/>Sale Date:" + SaleDate+ "<br/>Case Number:"+ CaseNumber+ "<br/>Address:"+ Addre\
ss+ "<br/>Zipcode:"+ ZipCode+ "<br/>Plaintiff:"+ Plaintiff+ "<br/>Defendant:"+ Defendant+ "<br/>Attorney:"+ Attorney+ "<br/>Sold to:"+ SoldTo+ "<br/>Parcel ID:"+ PID+ "<br/>Appraisal:"+ Appraisal+\
"<br/>Minimum bid:"+ MinBid+ "<br/>Sale amount:"+ SaleAmt+ "<br/> Sale status:"+ SaleStatus;
var icon = customIcons[SaleStatus] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, info);
markersArr.push(marker);
}
});
}
var customIcons = {
ACTIVE: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_green.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
CANCELLED: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_black.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
NOBIDNOSALE: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
SOLD: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
function clearLocations() {
infoWindow.close();
for (var i = 0; i < markers.length; i++) {
markersArr[i].setMap(null);
}
markersArr.length = 0;
}
function load() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(39.7620028,-84.3542049),
zoom: 10,
mapTypeId: 'roadmap'
});
infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
// downloadUrl("phpsqlajax_genxml3.php", function(data) {
downloadUrl( "phpsqlajax_genxml3dynamic.php?maxbid=54,000&minbid=0&salestatus=*&saledate=*", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var SaleDate = markers[i].getAttribute("SaleDate");
var CaseNumber = markers[i].getAttribute("CaseNumber");
var Address = markers[i].getAttribute("Address");
var ZipCode = markers[i].getAttribute("ZipCode");
var Plaintiff = markers[i].getAttribute("Plaintiff");
var Defendant = markers[i].getAttribute("Defendant");
var Attorney = markers[i].getAttribute("Attorney");
var SoldTo = markers[i].getAttribute("SoldTo");
var PID = markers[i].getAttribute("PID");
var Appraisal = markers[i].getAttribute("Appraisal");
var MinBid = markers[i].getAttribute("MinBid");
var SaleAmt = markers[i].getAttribute("SaleAmt");
var SaleStatus = markers[i].getAttribute("SaleStatus");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("Latitude")),
parseFloat(markers[i].getAttribute("Longitude")));
var info = "<b>Sale Date:" + SaleDate +"<br/>Address:"+ Address+"<br/>Sale Amount:" + SaleAmt + "</b> <br/>Sale Date:" + SaleDate+ "<br/>Case Number:"+ CaseNumber+ "<br/>Address:"+ Addre\
ss+ "<br/>Zipcode:"+ ZipCode+ "<br/>Plaintiff:"+ Plaintiff+ "<br/>Defendant:"+ Defendant+ "<br/>Attorney:"+ Attorney+ "<br/>Sold to:"+ SoldTo+ "<br/>Parcel ID:"+ PID+ "<br/>Appraisal:"+ Appraisal+\
"<br/>Minimum bid:"+ MinBid+ "<br/>Sale amount:"+ SaleAmt+ "<br/> Sale status:"+ SaleStatus;
var icon = customIcons[SaleStatus] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, info);
markersArr.push(marker);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
//]]>
</script>
</head>
<body onload="load()">
<form name='myForm'>
Min Bid $ :<input type='text' id='minbid' value='1,000' /> and
$ :<input type='text' id='maxbid' value='1,000,000' /> <br>
Sale Status:<select id='salestatus'>
<option value="*" selected>All</option>
<option>Active</option>
<option>Sold</option>
<option>Cancelled</option>
<option>No Bid, No Sale</option>
</select>
<br>
Sale Date:<select id='saledate'>
<option value="*" selected>All</option>
<option>2012-06-08</option>
<option>2012-06-01</option>
<option>2012-05-25</option>
<option>2012-05-18</option>
<option>2012-05-11</option>
<option>2012-05-04</option>
<option>2012-04-27</option>
<option>2012-04-20</option>
<option>2012-04-13</option>
<option>2012-04-06</option>
<option>2012-03-30</option>
<option>2012-03-23</option>
<option>2012-03-16</option>
<option>2012-03-09</option>
<option>2012-03-02</option>
</select>
<input type='button' onclick='updateMap()' value='Update Map' />
</form>
<div id="map" style="width: 95%; height: 85%"></div>
</body>
</html>
Again I'm 99.9% sure the php is fine since it returns valid results which are used to populate the field. I'm befuddled as to what I've done wrong for the update.
Hey SO this isn't spam let me post this dang question.
Your clearLocations function is looping over markers not markersArr which contains the existing marker references.
Should be
function clearLocations() {
infoWindow.close();
for (var i = 0; i < markersArr.length; i++) {
markersArr[i].setMap(null);
}
markersArr.length = 0;
}
On my website I have a form that allows users to register. It asks users to provide their city, state, and country. I also have a map that drops a marker for each user based on a lat/lng that's drawn from that city, state, country combination ($location).
Because I'm not being super specific (as in, I'm not asking for their ACTUAL address), I have a number of users that have the same lat/lng. And this creates a problem when trying to view markers on my map.
Should I use a clustering service? If so, do you have any suggestions?? Like I said, information flows from mySQL database --> XML --> PHP.
If so, it'll be clustered at the most zoomed level (like I said, same lat/lng). As a result, I'm going to need a info window that allows me to select each user at that particular location.
Ideas? Suggestions??? Much appreciated!!!
Jeremy
MarkerClusterer: http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/docs/examples.html
Or by hand (roughly - sample code only!)
var latlng = new google.maps.LatLng(-33.8671390, 151.2071140);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var markers = [];
var newmarkers = [];
for(var j=0; j<5; j++) {
markers.push({lat:-33.8671390, lng:151.2071140, title:'This is marker #' + i });
if(j==0) newmarkers.push(markers[j]);
for(var i=0; i<newmarkers.length; i++) {
if(newmarkers[i].lat == markers[j].lat && newmarkers[i].lng == markers[j].lng) {
newmarkers[i].title += ' AND ' + markers[j].title;
continue;
}
newmarkers.push(markers[j]);
}
}
for(var i=0; i<newmarkers.length; i++) {
var mkr = new google.maps.Marker({
position: new google.maps.LatLng(newmarkers[i].lat, newmarkers[i].lng),
map: map,
title: newmarkers[i].title
});
}
Thought I'd paste my code:
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(47.614495, -122.341861), 2);
map.enableScrollWheelZoom();
GDownloadUrl("world_xml.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var first_name = markers[i].getAttribute("first_name");
var last_name = markers[i].getAttribute("last_name");
var email = markers[i].getAttribute("email");
var affiliation = markers[i].getAttribute("affiliation");
var status = markers[i].getAttribute("status");
var service = markers[i].getAttribute("service");
var rank = markers[i].getAttribute("rank");
var specialty = markers[i].getAttribute("specialty");
var city = markers[i].getAttribute("city");
var state = markers[i].getAttribute("state");
var country = markers[i].getAttribute("country");
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var marker = createMarker(point, rank, first_name, last_name, email, affiliation, status, service, specialty, city, state, country);
map.addOverlay(marker);
}
});
}
}
function createMarker(point, rank, first_name, last_name, email, affiliation, status, service, specialty, city, state, country) {
var marker = new GMarker(point);
var html = "" + rank + " " + first_name + " " + last_name + " " + service + ", " + status + " " + specialty + " " + affiliation + " " + city + ", " + state + " " + country + " " + email + " " + " ";
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}