사용자의 위치를 가져 오려면 다음 코드를 시도합니다. 브라우저에서는 작동하지만 Windows 8 App 컴파일에서는 작동하지 않습니다.Google API는 브라우저에서 작동하며 Windows 8 앱에서는 작동하지 않습니다.
Java 런타임 오류 인 'Google'은 정의되지 않았습니다.
지도 API를로드하는 것이 좋습니다. 어떻게해야합니까? 적절한 코드와 대답을 부탁드립니다. 만족 스러울 때, 나는 분명히 투표 할 것입니다.
<!Doctype html>
<html>
<head>
<title>Get Location</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>
<body>
<p id="locResults">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
<script>
function getLocation(){
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{document.getElementById("locResults").innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
document.getElementById("locResults").innerHTML="Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
document.getElementById("locResults").innerHTML="Getting Your Location...";
getReverseGeocodingData(position.coords.latitude, position.coords.longitude);
}
function getReverseGeocodingData(lat, lng) {
var latlng = new google.maps.LatLng(lat, lng);
// This is making the Geocode request
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status !== google.maps.GeocoderStatus.OK) {
document.getElementById("locResults").innerHTML = status;
}
// This is checking to see if the Geoeode Status is OK before proceeding
if (status == google.maps.GeocoderStatus.OK) {
console.log(results);
var address = (results[0].formatted_address);
document.getElementById("locResults").innerHTML = address;
}
});
}
</script>
</body>
</html>
는 [문서]를보세요 (https://developers.google.com/maps/documentation/javascript/tutorial#Loading_the_Maps_API) – geocodezip