Have a quick question. On my website I have a form that allows users to input their city, state, and country. This information is converted to $lat and $lng, which is used to create a marker on a google map. Problem is, I have multiple users that select the same city. Clustering is a HUGE pain... to be honest, I can't seem to find a good tutorial and I'm feeling a bit hopeless.
So I thought I'd just modify each $lat and $lng slightly. For example, this is the info I get for Travis AFB, CA: lat="38.263065" lng="-121.949699". Wondering if it's possible to add a bit of code that might let me modify those last bits. Any suggestions???
Here's how I geocode $address (combination of $city, $state, $country):
$geocodestring=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' . urlencode($address) );
$geocodedinfo=json_decode($geocodestring);
$lat = $geocodedinfo->results[0]->geometry->location->lat;
$lng = $geocodedinfo->results[0]->geometry->location->lng;
And that information goes into my SQL database. This is the code that actually creates the map (pretty straightforward).
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(mar开发者_JAVA百科ker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
Any help/suggestions would be much appreciated!!!
Jeremy
markerclusterer for v2 may solve your problem.
Find code and examples here
http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/
精彩评论