package com.AndroidIntentGoogleMaps;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.Toast;
public class AndroidIntentGoogleMaps extends Activity {
EditText inputLatitude, inputLongitude;
SeekBar seekbarZoom;
Button buttonStartMaps;
final static float DEFAULT_Latitude = (float) 40.75773;
final static float DEFAULT_Longitude = (float) -73.985708;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
inputLatitude = (EditText)findViewById(R.id.Latitude);
inputLongitude = (EditText)findViewById(R.id.Longitude);
seekbarZoom = (SeekBar)findViewById(R.id.zoom);
buttonStartMaps = (Button)findViewById(R.id.startmaps);
inputLatitude.setText(String.valueOf(DEFAULT_Latitude));
inputLongitude.setText(String.valueOf(DEFAULT_Longitude));
buttonStartMaps.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String lat = inputLatitude.getText().toString();
String lon = inputLongitude.getText().toString();
String zoom = String.valueOf(seekbarZoom.getProgress()+1);
String strUri = "geo:"+lat+","+lon+"?z="+zoom;
Toast.makeText(AndroidIntentGoogleMaps.this, strUri, Toast.LENGTH_LONG).show();
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(strUri));
startActivity(intent);
}});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Latitude" />
<EditText
android:id="@+id/Latitude"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Longitude" />
<EditText
android:id="@+id/Longitude"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Zoom" />
<SeekBar
android:id="@+id/zoom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="22"
android:padding="10dp" />
<Button
android:id="@+id/startmaps"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start Google Maps" />
</LinearLayout>
相關文章:
- 使用意圖(Intent)啟動 Android 內建谷歌地圖的街景(StreetView)
沒有留言:
發佈留言