2012-12-07 2 views
0

Google지도를 자유로운 방법으로 사용하고 싶습니다. javacript를 실행하고 싶지만 이미지를 렌더링하고 싶지 않습니다. 오히려 파일에 데이터를 보내고 API가 제공해야하는 계산 기능 중 일부를 사용하여 텍스트 응답을 전달하려고합니다. 이 코드는 다음 코드로 시도했지만 자바 스크립트가 원격 웹 서비스가 아닌 브라우저에서 실행되므로이 ​​기능이 작동하지 않는다는 것을 깨달았습니다. 즉, 어떻게 원격 서버가 아래의 코드에서와 같은 '웹 서비스'를 호출하여 간단한 '예'또는 '아니오'응답을 얻는가를 목표로 제공 할 수 있습니다.Google지도를 사용하여 웹 서비스에 대한 결과를 생성하는 방법

<?php 

    // Get vars 
    $lat=$_GET["lat"]; 
    $lon=$_GET["lon"]; 

?> 



<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
    <style type="text/css"> 
     html { height: 100% } 
     body { height: 100%; margin: 0; padding: 0 } 
     #map_canvas { height: 100% } 
    </style> 
    <script type="text/javascript" 
     src="https://maps.googleapis.com/maps/api/js?key=MYKEYNOTYOURS:)&sensor=true&libraries=geometry"> 
    </script> 
    <script type="text/javascript"> 
// Poygon getBounds extension - google-maps-extensions 
// http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js 
if (!google.maps.Polygon.prototype.getBounds) { 
    google.maps.Polygon.prototype.getBounds = function(latLng) { 
    var bounds = new google.maps.LatLngBounds(); 
    var paths = this.getPaths(); 
    var path; 

    for (var p = 0; p < paths.getLength(); p++) { 
     path = paths.getAt(p); 
     for (var i = 0; i < path.getLength(); i++) { 
     bounds.extend(path.getAt(i)); 
     } 
    } 

    return bounds; 
    } 
} 

// Polygon containsLatLng - method to determine if a latLng is within a polygon 
google.maps.Polygon.prototype.containsLatLng = function(latLng) { 
    // Exclude points outside of bounds as there is no way they are in the poly 
    var bounds = this.getBounds(); 

    if(bounds != null && !bounds.contains(latLng)) { 
    return false; 
    } 

    // Raycast point in polygon method 
    var inPoly = false; 

    var numPaths = this.getPaths().getLength(); 
    for(var p = 0; p < numPaths; p++) { 
    var path = this.getPaths().getAt(p); 
    var numPoints = path.getLength(); 
    var j = numPoints-1; 

    for(var i=0; i < numPoints; i++) { 
     var vertex1 = path.getAt(i); 
     var vertex2 = path.getAt(j); 

     if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) { 
     if (vertex1.lat() + (latLng.lng() - vertex1.lng())/(vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) { 
      inPoly = !inPoly; 
     } 
     } 

     j = i; 
    } 
    } 

    return inPoly; 
} 


     function initialize() { 


     var mapOptions = { 
      center: new google.maps.LatLng(38.990842,-76.93625), 
      zoom: 17, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

     var box = [new google.maps.LatLng(38.9913160,-76.937079), 
     new google.maps.LatLng(38.991333,-76.936119), 
     new google.maps.LatLng(38.990287, -76.936108), 
     new google.maps.LatLng(38.990278,-76.937057), 
     new google.maps.LatLng(38.990495,-76.937052), 
     new google.maps.LatLng(38.990499,-76.936424), 
     new google.maps.LatLng(38.991091,-76.93643), 
     new google.maps.LatLng(38.991104,-76.937079) 
     ]; 

     var mPoint = [new google.maps.LatLng(38.991300,-76.936165)]; 

     var AVpoly = new google.maps.Polygon({path:box, 
      strokeColor:"#0000FF", 
      strokeOpacity:0.8, 
      strokeWeight:2, 
      fillColor:"#0000FF", 
      fillOpacity:0.4}); 

     var lat = <?php echo $lat; ?>; 
     var lon = <?php echo $lon; ?>; 

if(AVpoly.containsLatLng(new google.maps.LatLng(lat,lon), box) == true) { 
     document.write("Yes"); 
} 
else 
{ 
document.write("No"); 
} 

     } 



    </script> 
    </head> 
    <body onload="initialize()"> 
    <div id="map_canvas" style="width:100%; height:100%"></div> 
    </body> 
</html> 
+0

구글 맵이 자동 전송 정확히 내가 같은 웹 클라이언트 것을 AA 구글 맵 페이지를 설정 얼마나 귀하의 요구 사항 –

+0

그래서 무엇을 웹 서비스로 JSON 응답 (비 - 브라우저, php-server 같은 생각) POST로 요청을 할 수 있으며 '예'또는 '아니오'응답 만받습니다. 이것은 실제로 매우 쉽지만 위의 페이지를 변환하는 방법을 볼 수 없습니다. 간단한 문자열 만 반환하는 페이지 또는 전체 페이지가 아닌 단순한 JSON 개체로 반환합니다. 가능한 답변입니까? http://stackoverflow.com/questions/1045845/how-to-call-a-javascript-function- from-php? – WildBill

답변

2

허용되지 않습니다. 공개적으로 액세스 할 수있는지도를 표시하는 경우에만 Google지도 데이터를 사용할 수 있습니다. 참조 section 9.1 of the TOS10.1.1 (g) "No Use of Content without a Google Map. "

+0

절대적이고 만족스럽고 충분합니다. –

+0

아아, 작은 글씨 .... 감사합니다 :) – WildBill

+0

또한 자바 스크립트를 실현함으로써 겸손 해지고 있습니다. Google Maps api는 서버 측이 아니라 클라이언트 측에서 실행할 항목입니다. 나는 이것이 기술적으로 가능하다는 것을 확신하지 못합니다 ... – WildBill

관련 문제