2017-07-26 1 views
0

これは私のコードでマイナス私のAPIキーは、ユーザの現在位置を取得するには、それはChromeとFirefoxではなく、エッジに正確に動作します:MS-エッジでGoogleマップAPIと増加精度

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> 
 
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=[my api key]=3.exp"></script> 
 
<script type="text/javascript"> 
 
function getMyLocation(){ 
 
\t /* Chrome need SSL! */ 
 
\t var is_chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase()); 
 
\t var is_ssl = 'https:' == document.location.protocol; 
 
\t if(is_chrome && ! is_ssl){ 
 
\t \t return false; 
 
\t } 
 
\t /* HTML5 Geolocation */ 
 
\t navigator.geolocation.getCurrentPosition(
 
\t \t function(position){ // success cb 
 
\t \t \t /* Current Coordinate */ 
 
\t \t \t var lat = position.coords.latitude; 
 
\t \t \t var lng = position.coords.longitude; 
 
\t \t \t var google_map_pos = new google.maps.LatLng(lat, lng); 
 
\t \t \t /* Use Geocoder to get address */ 
 
\t \t \t var google_maps_geocoder = new google.maps.Geocoder(); 
 
\t \t \t google_maps_geocoder.geocode(
 
\t \t \t \t { 'latLng': google_map_pos }, 
 
\t \t \t \t function(results, status) { 
 
\t \t \t \t \t if (status == google.maps.GeocoderStatus.OK && results[0]) { 
 
\t \t \t \t \t \t document.getElementById("myplace").innerHTML = results[0].formatted_address; 
 
\t \t \t \t \t \t var str = results[0].formatted_address; 
 
\t \t \t \t \t \t var res = str.split(", "); 
 
\t \t \t \t \t \t /*Street*/ 
 
\t \t \t \t \t \t document.getElementById('input_14_10').value = res[0]; 
 
\t \t \t \t \t \t /*City*/ 
 
\t \t \t \t \t \t document.getElementById('input_14_12').value = res[1]; 
 
\t \t \t \t \t \t /*State*/ 
 
\t \t \t \t \t \t document.getElementById('input_14_13').value = res[2].substr(0,2); 
 
\t \t \t \t \t \t /*Zip*/ 
 
\t \t \t \t \t \t document.getElementById('input_14_15').value = res[2].substr(3); 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t); 
 
\t \t }, 
 
\t \t function(){ // fail cb 
 
\t \t } 
 
\t); 
 
}; 
 
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
 
<head> 
 
\t <title>title</title> 
 
\t <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 
\t <meta name="description" content="" /> 
 
\t <meta name="keywords" content="" /> 
 
\t <meta name="robots" content="index,follow" /> 
 
\t <link rel="stylesheet" type="text/css" href="styles.css" /> 
 
</head> 
 
<body> 
 
<input type="button" id='calcmiles' onclick='getMyLocation()' value='Push to Get My Location' ><br> 
 
<font style="font-size: 200% !important"><b><a id='myplace'></a></b></font> 
 
    <input type="hidden" class="field" id="street_number" disabled="true"></input> 
 
    <input type="hidden" class="field" id="route" disabled="true"></input> 
 
    <input type="hidden" class="field" id="country" disabled="true"></input> 
 
<table id="address"> 
 
    <tr> 
 
     <td class="label">Street address</td> 
 
     <td class="wideField" colspan="2"><input class="field" id="input_14_10" disabled="true"></input></td> 
 
     </tr> 
 
     <tr> 
 
     <td class="label">City</td> 
 
     <td class="wideField" colspan="3"><input class="field" id="input_14_12" disabled="true"></input></td> 
 
     </tr> 
 
     <tr> 
 
     <td class="label">State</td> 
 
     <td class="slimField"><input class="field" id="input_14_13" disabled="true"></input></td> 
 
     <td class="label">Zip code</td> 
 
     <td class="wideField"><input class="field" id="input_14_15" disabled="true"></input></td> 
 
     <tr> 
 
     <td class="label">Phone Number</td> 
 
     <td class="wideField"><input class="field" id="phone"></input></td> 
 
     </tr> 
 
     </tr> 
 
</table> 
 
</body> 
 
</html>

ChromeとFirefoxでは、ユーザーの現在の場所が一貫して正しく表示されますが、Edgeではいくつかのアドレスがずれています。エッジの精度を上げるために何ができるのですか?

+0

Edgeからウェブアプリを使用しているときにGoogleのアカウントにログオンしていることを確認してください...おそらくGoogleマップapiは、ジオロケーションクエリが匿名のGoogleユーザーから来た場合、精度が低下する可能性があります。 InPrivateとシークレット版のブラウザを使用してテストします。 –

答えて

0

Geolocation.getCurrentPosition()と異なる緯度/経度を取得している場合、またはジオコードされた結果と異なる結果が得られた場合は、ご存じですか?

Lat/Lonが異なる場合は、オプションのPositionOptionsオブジェクトをgetCurrentPosition()に渡すこともできます。 PositionsOptionsは、Edgeからより良い結果を得るかもしれないenableHighAccuracyのフラグをとります。

は、次のような最後のパラメータとして渡す:これが問題になる場合

var options = { 
    enableHighAccuracy: true, 
    timeout: 5000, 
    maximumAge: 0 
}; 

navigator.geolocation.getCurrentPosition(
    function(position){ // success cb); 
    // ...your function 
    }, 
    function(){ } // fail cb, 
    options 
) 

わからないが、試してみる価値。

関連する問題