2012-01-20 23 views
3

私はFlashで小さなWebアプリケーションを構築しています。ユーザーのジオロケーションを取得するソリューションはありますか?地理位置情報

答えて

3

最も簡単な方法は、JavaScript関数とのインタフェースです。あなたのHTMLで

:あなたのマップが作成されると

<script> 
     function getGEO() 
     { 
      // First check if your browser supports the geolocation API 
      if (navigator.geolocation) 
      { 
       //alert("HTML 5 is getting your location"); 
       // Get the current position 
       navigator.geolocation.getCurrentPosition(function(position) 
       { 
        lat = position.coords.latitude 
        long = position.coords.longitude; 
        // Pass the coordinates to Flash 
        passGEOToSWF(lat, long); 
       }); 
      } else { 
       //alert("Sorry... your browser does not support the HTML5 GeoLocation API"); 
      } 
     } 
     function passGEOToSWF(lat,long) 
     { 
      //alert("HTML 5 is sending your location to Flash"); 
      // Pass the coordinates to mySWF using ExternalInterface 
      document.getElementById("index").passGEOToSWF(lat,long); 
     } 
    </script> 

次に、あなたのアプリケーションでは、機能でこれを置く:

 //for getting a user's location 
      if (ExternalInterface.available) 
      { 
       //check if external interface is available 
       try 
       { 
        // add Callback for the passGEOToSWF Javascript function 
        ExternalInterface.addCallback("passGEOToSWF", onPassGEOToSWF); 
       } 
       catch (error:SecurityError) 
       { 
        // Alert the user of a SecurityError 
       } 
       catch (error:Error) 
       { 
        // Alert the user of an Error 
       } 
      } 

を最後に、キャッチする準備ができて、民間の機能を持っています折り返し電話。

private function onPassGEOToSWF(lat:*,long:*):void 
    { 
     userLoc = new LatLng(lat,long); 
     map.setCenter(userLoc); 

    } 
+0

恐ろしいです!ありがとうございました。 Adobe Airデスクトップアプリケーションからジオロケーションを取得する方法も知っていますか? – Uli

+0

決して空気と一緒に働いたので、残念ながら、いいえ。 –

+0

くそー、私は回避策があると思った。しかし、ありがとう。 – Uli

関連する問題