2013-12-22 1 views
-1

사용자의 위치를 ​​가져 오려면 다음 코드를 시도합니다. 브라우저에서는 작동하지만 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> 
+0

는 [문서]를보세요 (https://developers.google.com/maps/documentation/javascript/tutorial#Loading_the_Maps_API) – geocodezip

답변

0

당신은 Google지도 전화하는 것을 잊었다 :

function initialize() { 
     var mapOptions = { 
      center: new google.maps.LatLng(16.4706001, -33.6728973), 
      zoom:3, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
     var map = new google.maps.Map(document.getElementById("map-canvas"), 
      mapOptions); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 
+0

감사합니다 답장을 보내지 만 여전히 동일한 오류 메시지가 표시됩니다. Google은 정의되지 않았습니다. 더 이상의 팁? – tika

+0

코드에 API 키가 없다면 어떤 의미가 있습니다. 다른 것은 API의 다른 객체를 사용하기 전에 순서를 확인하고 브라우저에 'google'이 무엇인지 알려주는 것입니다. 그냥. – user3062745

관련 문제