При посещении сайта http://www.dentalo.se вы должны увидеть это изображение.
Я звоню в RestService по адресу http://www.dentalo.se/RestService/Dentalo.svc/Companies, и я знаю, что он работает и получает ответ. Я проверил сервис.
Я использую Карты Google для отображения местоположения для карт Google. Он отображает местоположение при использовании браузера Chrome. Но я не могу понять, почему он не работает в Firefox, Internet Explorer. На мобильных устройствах он не работает ни на одном браузере, ни на хром.
Это сообщение об ошибке, которое я получаю в Firefox. Если вы просто посетите http://www.dentalo.se, вы увидите ошибку. Я хочу только добавить соответствующий код. Если вам нужно больше кода, скажите мне.
sg = [object Object], url = error, line = [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://dentalo.se/assets/plugins/jquery- 1.10.2.min.js ::.send :: line 6 "data: no]
Этот код JavaScript, который я включил.
<script src="/assets/plugins/jquery-1.10.2.min.js" type="text/javascript"></script>
<!-- Start Google Map JavaScript -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&language=sv"></script>
<script src="/assets/plugins/gmaps/gmaps.js" type="text/javascript"></script>
<!-- End Google Map JavaScript -->
более короткая версия кода JavaScript
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(ShowPosition);
}
else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
function showError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case error.TIMEOUT:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}
function ShowPosition(position) {
//begin rest call
$("#latitude").val(position.coords.latitude);
$("#longitude").val(position.coords.longitude);
$.ajax({
type: "GET",
cache: false,
async: false,
url: "http://www.dentalo.se/RestService/Dentalo.svc/Companies",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
map = new GMaps({
el: '#map',
lat: position.coords.latitude,
lng: position.coords.longitude,
zoom: 15,
zoomControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControlOpt: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.RIGHT_TOP
},
panControl: true,
scrollwheel: true
});
map.addMarker({
lat: position.coords.latitude,
lng: position.coords.longitude,
title: 'Min position',
icon: 'http://www.dentalo.se/assets/img/map/user_x64.png'
});
$.each(data, function (index, item) {
map.addMarker({
lat: item.Latitude ,
lng: item.Longitude ,
title: item.Address ,
icon: GetMarkerImage(item.Status),
infoWindow: {
content: '<div style="width: 300px"><h4>' + item.Name + '</h4><br /><p>' + item.Address + ', ' + item.County.Name + '</p><div class="four columns alpha"><a class="btn blue ' + SetDisplayClass(item.Status) + '" href="booking/' + item.CompanyId + '" ><i class="m-icon-swapright m-icon-white"></i> Boka</a> <a href="#" onClick="showPopUp('' + item.CompanyId +'');return false;" class="btn default">Information</a></div></div>',
}
})
});
},
error: function (msg, url, line) {
//alert('error trapped in error: function(msg, url, line)');
alert('msg = ' + msg + ', url = ' + url + ', line = ' + line);
}
});
Большое спасибо.
* Начать редактирование *
Я решил проблему. Это проблема Url. В вызове ajax для службы отдыха вам не нужно указывать полный URL.
Вы должны сделать это так
Я меняю эту строку
url: " http://www.dentalo.se/RestService/Dentalo.svc/Companies ",
к
url: "RestService/Dentalo.svc/Компании",
$.ajax({
type: "GET",
cache: false,
async: false,
url: "RestService/Dentalo.svc/Companies",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
map = new GMaps({
el: '#map',
lat: position.coords.latitude,
lng: position.coords.longitude,
zoom: 15,
zoomControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControlOpt: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.RIGHT_TOP
},
panControl: true,
scrollwheel: true
});
map.addMarker({
lat: position.coords.latitude,
lng: position.coords.longitude,
title: 'Min position',
icon: 'http://www.dentalo.se/assets/img/map/user_x64.png'
});
$.each(data, function (index, item) {
map.addMarker({
lat: item.Latitude ,
lng: item.Longitude ,
title: item.Address ,
icon: GetMarkerImage(item.Status),
infoWindow: {
content: '<div style="width: 300px"><h4>' + item.Name + '</h4><br /><p>' + item.Address + ', ' + item.County.Name + '</p><div class="four columns alpha"><a class="btn blue ' + SetDisplayClass(item.Status) + '" href="booking/' + item.CompanyId + '" ><i class="m-icon-swapright m-icon-white"></i> Boka</a> <a href="#" onClick="showPopUp('' + item.CompanyId +'');return false;" class="btn default">Information</a></div></div>',
}
})
});
},
error: function (msg, url, line) {
//alert('error trapped in error: function(msg, url, line)');
alert('msg = ' + msg + ', url = ' + url + ', line = ' + line);
}
});
* End Edit *
метод getCurrentPosition
по умолчанию имеет бесконечный тайм-аут. Попробуй это:
navigator.geolocation.getCurrentPosition(ShowPosition, showError, {timeout:2000})
В этом объекте можно установить еще два параметра: enableHighAccuracy
и maximumAge
Ознакомьтесь с: http://diveintohtml5.info/geolocation.html для получения дополнительной информации.