问题
Hi I am currently playing with geolocation and it works great with everything except IE as it doesn't seem to support Google and wants to use Bing does anyone know how to make the directions IE friendly...its been bugging me for days!!
Heres my code:
function fallback() {
var myOptions = {
center: new google.maps.LatLng(51.43255949795703, - 0.461750328540802),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("Map_Canvas"),
myOptions);
var markerPos = new google.maps.LatLng(51.43255949795703, - 0.461750328540802);
var marker = new google.maps.Marker({
position: markerPos,
map: map,
title: "The Harpers Hairdressing"
});
}
function initGeolocation() {
if (navigator.geolocation) {
// Call getCurrentPosition with success and failure callbacks
navigator.geolocation.getCurrentPosition(success, fail);
} else {
fallback()
}
}
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function success(position) {
directionsDisplay = new google.maps.DirectionsRenderer();
coords = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var myOptions = {
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: coords
}
map = new google.maps.Map(document.getElementById("Map_Canvas"),
myOptions);
directionsDisplay.setMap(map);
calcRoute();
}
function calcRoute() {
var start = coords;
var end = new google.maps.LatLng(51.43255949795703, - 0.461750328540802);
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function (result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
}
function fail() {
fallback();
}
回答1:
A quick search reveals IE9 is supposed to support geolocation, but it is not as accurate as other browsers. For IE8 and older it looks like you would have to use a "polyfill", e.g. Webshims.
来源:https://stackoverflow.com/questions/12451150/geolocation-with-both-bing-and-google-because-of-internet-explorer