金子邦彦研究室プログラミングJavaScript による Web プログラミングAndroid で JavaScript を使ってみる

Android で JavaScript を使ってみる

GPS 情報を取得してみる(書きかけ)

package hoge.hoge.com;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;
import android.location.Location;
import android.location.LocationManager;

public class HelloActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        LocationManager locman = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
        Location loc = locman.getLastKnownLocation(LOCATION_SERVICE);
        double latitude = loc.getLatitude();//緯度
        double longitude = loc.getLongitude();//経度
        
        TextView  tv = new TextView(this);
        tv.setText( "lat: " + latitude + ", long: " + longitude );
        setContentView(tv);
    }
}

JavaScript を使ってみる