-5

MainActivity にある次のコードを操作し、結果を別のアクティビティにプルして、' http://www.website.com?lat:lng: speed:bearing ' は、引き出された値に基づきます。

locationCheck() は、URL を作成するために見つかった場所を使用したい JSONParse アクティビティがあるにもかかわらず、Mainactivity に配置されます。私がしていないのは、結果を共有する方法です。

HTML または PHP では、グローバル値を使用します。

create を呼び出して乾杯することはできますが、結果を共有する最善の方法が見つかりませんでした。

public void locationCheck() {
        MyLocation myLocation = new MyLocation();       
        // this is the result
        myLocation.getLocation(this, locationResult);
    }

    public LocationResult locationResult = new LocationResult() {
        public void gotLocation(final Location location) {
            try {
                double lat = location.getLatitude();
                double lng = location.getLongitude();
                if (lat != 0.0 && lng != 0.0) {

                    String sLat;
                    String sLng;
                    sLat = Double.toString(lat);
                    sLng = Double.toString(lng);
                    String gps_location = sLat + " : " + sLng;
                    Toast.makeText(getBaseContext(),
                            "We got gps location! " + gps_location + "",
                            Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {

            }
        }
    };
4

1 に答える 1

0

次の例では、ロケーション アクティビティを実行し、その結果をグローバルにアクセス可能なフォームに文字列として投稿できます。これにより、別のアクティビティを通じてコン​​テキスト認識 URL を作成する形式で使用できるようになります...

ご覧のとおり、トーストはグローバル値を使用しているため、アクセス可能な場所でテストできました。

メインアクティビティでは....

public void locationCheck() {
    MyLocation myLocation = new MyLocation();       
    // this is the result
    myLocation.getLocation(this, locationResult);
}

public LocationResult locationResult = new LocationResult() {
    public void gotLocation(final Location location) {
        try {
            double lat = location.getLatitude();
            double lng = location.getLongitude();
            double bearing = location.getBearing();
            double speed = location.getSpeed();
            if (lat != 0.0 && lng != 0.0) {

                String sLat;
                String sLng;
                String sBearing;
                String sSpeed;  

                sLat = Double.toString(lat);
                sLng = Double.toString(lng);
                sBearing = Double.toString(bearing);
                sSpeed = Double.toString(speed);

                // send to global vars

                Globals.glat = sLat;
                Globals.glng = sLng;
                Globals.gBearing = sBearing;
                Globals.gSpeed = sSpeed;    

                String gps_location = Globals.glat + " : " + Globals.glng;

                @SuppressWarnings("unused")
                String gps_location2 = sBearing + " : " + sSpeed;

                Toast.makeText(getBaseContext(),
                        "We got gps location! " + gps_location + "",
                        Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {

        }
    }
};

グローバル活動では

// Global Values
// http://stackoverflow.com/questions/3100726/sharing-global-variables-across-activities-problem-when-using-a-webview
// http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables?rq=1

   public class Globals {

   static String glat; 
   static String glng;
   static String gBearing;
   static String gSpeed;

}
于 2013-05-12T21:22:32.073 に答える