2012-09-29 2 views
0

Gmap3-Jquery plugin을 사용하여 웹 응용 프로그램 중 하나에서 Google지도를 생성합니다. 현재 로컬 드라이브에 Google API을 다운로드하고 HTML 페이지에서이 드라이브를 사용합니다.얼마 후 Google API 3이 만료됩니다.

그러나 모든 작업이 정상적으로 작동하지만 3-4 일 후에 Google API가 작동을 멈 춥니 다. 내 로컬 드라이브에 동일한 링크에서 신선한 Google API를 다운로드하면 모든 것이 정상적으로 작동합니다. 그런 문제의 원인은 무엇일까요? API 키 때문입니까? 아니면 내 로컬 드라이브에 다운로드하여 로컬에서 참조하기 때문에입니까?

하지만 API 키가 필요없는 Google지도 API3을 다운로드 중입니다.

<script src="/site_media/js/google-map.js" type="text/javascript"></script> 
<script type="text/javascript" src="/site_media/js/gmap3.js"></script> 
<script type="text/javascript"> 
    $(function(){ 
    $('#facility_map').gmap3(
     {  
     action:'init', 
     options:{ 
       center:[26.327475, 50.20134], 
      zoom: 18, 
       mapTypeId: google.maps.MapTypeId.HYBRID 
      } 
     },  
      { 
    action:'getRoute', 
    options:{ 
       origin:['26.327475', '50.20134'], 
       destination:['{{facility.latitude}}', '{{facility.longitude}}'], 
      travelMode: google.maps.DirectionsTravelMode.DRIVING 
       }, 
    callback: function(results) 
     { 
      if (!results) return; 
      $(this).gmap3(
      { 
       action:'addDirectionsRenderer', 
       options:{  
          preserveViewport: true,   
       directions:results 
        } 
      }); 
     } 
    }, 
      { 
      action:'getDistance', 
      options:{ 
         origins:[['26.327475', '50.20134']], 
       destinations:[['{{facility.latitude}}', '{{facility.longitude}}']], 
       travelMode: google.maps.TravelMode.DRIVING 
      }, 
     callback: function(results) 
     { 
     var html = ''; 
     if (results) 
      { 
      for (var i = 0; i < results.rows.length; i++) 
      { 
     var elements = results.rows[i].elements; 
     for(var j=0; j<elements.length; j++) 
     { 
      switch(elements[j].status) 
      { 
      case google.maps.DistanceMatrixStatus.OK: 
        html += results.destinationAddresses[j]+" -<b> "+elements[j].distance.text + ' (' + elements[j].duration.text + '</b>)<br />'; 
      break; 
      case google.maps.DistanceMatrixStatus.NOT_FOUND: 
       html += 'The origin and/or destination of this pairing could not be geocoded<br />'; 
      break; 
      case google.maps.DistanceMatrixStatus.ZERO_RESULTS: 
        html += 'No route could be found between the origin and destination.<br />'; 
       break; 
      } 
     } 
     } 
     } 
     else 
     { 
      html = 'error'; 
     } 
     $('#distance_msg').html("Distance From Rezayat Head Office Khobar to "+html); 
     } 
    } 
    ); 
    }); 


</script> 

답변

1

당신이 당신의 하드 드라이브/웹 응용 프로그램에 다음 파일을 저장 위치 : 님의

http://maps.google.com/maps/api/js?sensor=false

그렇다면, 그 대답은 여기에

코드입니다 귀하의 질문 ...

또는 내 로컬 드라이브에 다운로드했기 때문에 로컬에서 을 참조 했습니까?

은 ... 예이다.

참조하는 파일이 캐시되어 항상 변경됩니다. 위에서 언급 한 jQuery지도 플러그인을 사용한 적이 한번도 없었지만 API를 살펴보면 Google에서 해당 스크립트를 호출하고 직접 저장하지 말아야한다고 언급했습니다.

또한 Google에서 JS로드 및 대역폭을 처리하고 로컬로 저장하지 않도록하십시오. API가 변경 될 수 있으며 캐시 된 버전에서는지도가 최신 버전을로드하지 않아 중단 될 수 있습니다. 도 Google load your jQuery하자 - 사이트를 사용하는 사람들이 더 나은 경험이있을 것이다 :

또한 한 가지 더 추가 할 것입니다. 이 기사에서는 why에 대해 자세히 설명합니다.

+0

지도 API를 부트 스트랩 파일은 특별히이를 방지하기 위해 모든 너무 많은 시간을 무효화 코드가 포함되어 있습니다. –

+0

@Chand Killingsworth :지도 API를 외부에서 참조해야합니까? 로컬 드라이브에서 참조하는 대신 URL을 통해? – Asif

+0

예, 외부에서 참조해야합니다. – JohnnyCoder