0

I have managed to get the Google Maps API working with a mySQL database.

It is pretty much as I wanted it, but just noticed that the zoom bar is not displaying correctly:

http://www.quakerquest.org/meeting_place_search/

Any suggestions how to fix this? Thanks.

The Google API code is

<script type="text/javascript">
//<![CDATA[
var map;
var markers = [];
var infoWindow;
var locationSelect;

function load() {
  map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(53.3836, -1.4665),
    zoom: 6,
    mapTypeId: 'roadmap',
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
  });
  infoWindow = new google.maps.InfoWindow();

  locationSelect = document.getElementById("locationSelect");
  locationSelect.onchange = function() {
    var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
    if (markerNum != "none"){
      google.maps.event.trigger(markers[markerNum], 'click');
    }
  };
}

function searchLocations() {
 var address = document.getElementById("addressInput").value;
 var geocoder = new google.maps.Geocoder();
 geocoder.geocode({address: address}, function(results, status) {
   if (status == google.maps.GeocoderStatus.OK) {
    searchLocationsNear(results[0].geometry.location);
   } else {
     alert(address + ' not found');
   }
 });
 }

function clearLocations()  {
 infoWindow.close();
 for (var i = 0; i < markers.length; i++) {
   markers[i].setMap(null);
 }
 markers.length = 0;

 locationSelect.innerHTML = "";
 var option = document.createElement("option");
 option.value = "none";
 option.innerHTML = "Select a meeting house:";
 locationSelect.appendChild(option);
}

function searchLocationsNear(center) {
 clearLocations();

 var radius = document.getElementById('radiusSelect').value;
 var searchUrl = 'phpsqlsearch_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
 downloadUrl(searchUrl, function(data) {
   var xml = parseXml(data);
   var markerNodes = xml.documentElement.getElementsByTagName("marker");
   var bounds = new google.maps.LatLngBounds();
   for (var i = 0; i < markerNodes.length; i++) {
     var name = markerNodes[i].getAttribute("Venue");
     var nameID = markerNodes[i].getAttribute("VenueID");
     var address = markerNodes[i].getAttribute("address");
     var distance = parseFloat(markerNodes[i].getAttribute("distance"));
     var latlng = new google.maps.LatLng(
          parseFloat(markerNodes[i].getAttribute("lat")),
          parseFloat(markerNodes[i].getAttribute("lng")));

     createOption(name, distance, i);
     createMarker(latlng, name, nameID, address);
     bounds.extend(latlng);
   }
   map.fitBounds(bounds);
   locationSelect.style.visibility = "visible";
   locationSelect.onchange = function() {
     var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
     google.maps.event.trigger(markers[markerNum], 'click');
   };
  });
}

function createMarker(latlng, name, nameID, address) {



  var html = "<a href='http://www.quakerquest.org/meeting_place_details/index.php?VenueID="+nameID+"'>" + name + "</a> <br/>" + address;



  var marker = new google.maps.Marker({
    map: map,
    position: latlng
  });
  google.maps.event.addListener(marker, 'click', function() {
    infoWindow.setContent(html);
    infoWindow.open(map, marker);
  });
  markers.push(marker);
}

function createOption(name, distance, num) {
  var option = document.createElement("option");
  option.value = num;
  option.innerHTML = name + "(" + distance.toFixed(1) + ")";
  locationSelect.appendChild(option);
}

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.responseText, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}

function parseXml(str) {
  if (window.ActiveXObject) {
    var doc = new ActiveXObject('Microsoft.XMLDOM');
    doc.loadXML(str);
    return doc;
  } else if (window.DOMParser) {
    return (new DOMParser).parseFromString(str, 'text/xml');
  }
}

function doNothing() {}

//]]>

And the HTML to display the map:

<div id="map" style="width:100%; height: 40%"></div>
Iain71
  • 13
  • 3
  • Hi, can you please post some of the relevant code here? (i.e. how you are initializing the Google Map). See here for details: http://meta.stackoverflow.com/questions/254428/ thanks! – Pekka Mar 24 '15 at 19:57
  • Have added the API code now. – Iain71 Mar 24 '15 at 20:20
  • Really sorry about posting a duplicate. I did search 'Google Maps API zoom' and didn't spot anything obvious in the first few pages. So unfortunately I am unable to explain in what way this differs. If you know the question has already been answered a link to the answer might have been helpful. – Iain71 Mar 25 '15 at 11:11

1 Answers1

0

I remember encountering this annoying issue.

Apparently google maps does not like

img {
   max-width: 100%;
}

(Usually from bootstrap or other css resets)

Add this to your css to fix:

#map img {
  max-width: none;
}

Not sure why it works, but it does.

Bryant Miano
  • 689
  • 3
  • 9