1

I have built a fusion table with a geo location search.

Right now, my search function centers on the results of the geocoded address. I would like the map to detect the nearest marker and zoom out/in depending on how far away the nearest marker is. For example, if there is a marker in Colorado, but you are searching an address in Wyoming, your search will render a map big enough to show you your location AND the nearest marker. However, if you are in Los Angeles, and you are searching in Los Angeles, the map will zoom in to include all of the markers in the area, not the markers in surrounding cities/states.

Any ideas on how to accomplish this?

Here is my code:

var map, layer;
var geocoder;

function initialize(location) {

console.log(location);
geocoder = new google.maps.Geocoder();
var userlocation = new google.maps.LatLng(location.coords.latitude, location.coords.longitude);

map = new google.maps.Map(document.getElementById('map-canvas'), {
center: userlocation,
zoom: 8
});

layer = new google.maps.FusionTablesLayer({
query: {
  select: '\'Geocodable address\'',
  from: '1x265dMvUClEGEVHD_3VRBvSRXk-mbs4jcO2xy29K',
}                                     
});
layer.setMap(map);
}

function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
  map.setCenter(results[0].geometry.location);
} else {
  alert('Geocode was not successful for the following reason: ' + status);
}
});
}

navigator.geolocation.getCurrentPosition(initialize);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.