I wrote a code using the example of the google maps with php and mysqli, the code is working in other browsers but in the chrome whe I load this program the map displays and turns into blue or grey without markers. I am getting the grey screen or some times blue screen when I load this page in chrome browser.but the results will show inside div. After clearing the location settings,the markers appears. I have posted my code Please check it if I have missed anything.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>Services Near To You</title>
<script src="https://maps.googleapis.com/maps/api/js?key="
type="text/javascript"></script>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
</script>
<script type="text/javascript">
//<![CDATA[
var map;
var markers = [];
var infoWindow;
var locationSelect;
$(document).ready(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showLocation);
} else {
$('#location').html('Geolocation is not supported by this browser.');
}
});
/*$(document).ready(function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(newLocation);
} else {
alert("Geolocation is not supported by this browser.");
}
}
function newLocation(position) {
alert(position.longitude);
}*/
function showLocation(position) {
var lati = position.coords.latitude;
var lngi = position.coords.longitude;
load(lati,lngi);
}
function load(lati,lngi) {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(lati,lngi),
zoom: 10,
mapTypeId: 'roadmap',
mapTypeControlOptions: {style:
google.maps.MapTypeControlStyle.DROPDOWN_MENU}
});
infoWindow = new google.maps.InfoWindow();
locationSelect = document.getElementById("locationSelect");
searchLocationsNear(lati,lngi);
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 = "See all results:";
locationSelect.appendChild(option);
}
function searchLocationsNear(lati,lngi) {
clearLocations();
var radius = 2;
//var radius = document.getElementById('radi').value;
var searchUrl = 'sn.php?lat=' + lati + '&lng=' + lngi + '&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("name");
var address = markerNodes[i].getAttribute("address");
var icn = markerNodes[i].getAttribute("icon");
var offers = markerNodes[i].getAttribute("offers");
var link = markerNodes[i].getAttribute("link");
var cat = markerNodes[i].getAttribute("cat");
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, address,icn,offers,link,cat);
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, address,icn,offers,link,cat) {
var html = "<b><u>Service Category</u> :" + cat + "</b>" + "</br>" + "<b>"
+ name + "</b><br/>" + address + "</br><b>OFFERS: " +offers +"</b> </br>"+"
<a href= " + link +" ><center>View Member</center></a>" ;
var iconBase = 'https://freerewards2u.com/cicons/'+ icn;
var marker = new google.maps.Marker({
map: map,
position: latlng,
icon:iconBase
});
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() {}
//]]>
</script>
</head>
<style>
div.polaroid {
width: 300px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0,0.19);
text-align: center;
}
</style>
<body style="margin:0px; padding:0px;" onload="load()">
<div><select id="locationSelect" style="width:100%;visibility:hidden">
</select></div>
<center><div class="polaroid" id="map" style="width: 75%; height: 75%">
</div></center>
</body>
</html>