사용자의 현재 위치를 얻으려면 google geolocation의 getCurrentPosition() 함수를 사용하고 있습니다.Google지도 geolocation getcurrentposition()
파이어 폭스에서는 잘 작동하지만 크롬에서는 작동하지 않습니다.
내 코드는 다음과 같습니다 :
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<p id="demo">Click the button to get your position.</p>
<button onclick="getLocation()">Try It</button>
<div id="mapholder"></div>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showtemp);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var latlon = position.coords.latitude + "," + position.coords.longitude;
var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="
+latlon+"&key=AIzaSyDOgvRydLLNrztjgagobYS_sROK1u3r4M4&zoom=14&size=400x300&sensor=false";
document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";
}
function showtemp(temp) {
alert("test");
}
function showError(error) {
$.get("http://ipinfo.io", function (response) {
var array = (response.loc).split(',');
console.log(array[0]);
var latlon = array[0] + "," + array[1];
var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="
+latlon+"&zoom=14&size=400x300&sensor=false";
document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";
}, "jsonp");
}
</script>
</body>
</html>
날이 문제를 해결 도와주세요.
오류 : "getCurrentPosition() 및 watchPosition()이 불안정한 출처에서 사용되지 않으며 향후 지원이 제거 될 예정이므로 응용 프로그램을 HTTPS와 같은 안전한 출처로 전환하는 것을 고려해야합니다." 사전
크롬에서 작동하지 않습니다. 콘솔에서 오류가 발생하는 것보다 효과적입니다. 크롬의 콘솔 오류로 질문을 업데이트 하시겠습니까 ?? – Bhavin
getcurrentposition()이 삭제되고 대체 할 수 없습니다.이 답변을 읽으십시오 : - [getcurrentposition-and-watchposition-are-deprecated-on-insecure-origins] (http://stackoverflow.com/questions/32106849/getcurrentposition-and-watchposition-are-deprecated-on-insecure-origins) – Bhavin
최신 크롬 버전 = 52로 작업 할 수있는 방법이 있습니까? –