[안드로이드] 지도 보기 기본 소스 (예제)
MainActivity.java
package com.example.test13;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity {
private EditText lat;
private EditText lon;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.map);
lat = (EditText) findViewById(R.id.lat);
lon = (EditText) findViewById(R.id.lon);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view)
{
String _lat=lat.getText().toString();
String _lon=lon.getText().toString();
Uri uri = Uri.parse("geo:"+_lat+", "+_lon);
startActivity ( new Intent ( Intent.ACTION_VIEW, uri));
}
});
}
}
Activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="true"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test13.MainActivity" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,2" >
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="2dip"
android:paddingRight="4dip"
android:text=" 위도 경도 : " />
<EditText
android:id="@+id/lat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="true"
android:editable="true"
android:singleLine="true" />
<EditText
android:id="@+id/lon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="true"
android:editable="true"
android:singleLine="true" />
</TableRow>
</TableLayout>
<Button
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="지도 보기!" />
</LinearLayout>