Explorer而使用bing和google进行地理定位

Explorer而使用bing和google进行地理定位

本文介绍了由于Internet Explorer而使用bing和google进行地理定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我目前正在玩地理位置,它与除IE之外的所有东西都很好,因为它似乎不支持谷歌,并希望使用Bing有人知道如何使方向IE友好......它一直在窃听我天!!!

继承我的代码:

  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
});
}

函数initGeolocation(){
if(navigator.geolocation){
//调用带成功和失败回调的getCurrentPosition
navigator.geolocation。 getCurrentPosition(成功,失败);
} else {
fallback()
}
}
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

函数成功(位置){
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();
}

函数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);
}
});
}

函数失败(){
fallback();
}


解决方案

应该支持地理位置,但并不像其他浏览器那么精确。对于IE8及更高版本,看起来您必须使用polyfill,例如。


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();
}
解决方案

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.

这篇关于由于Internet Explorer而使用bing和google进行地理定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:47