티스토리 뷰
반응형
// Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pkg.LocationShare"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".LocationShare"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
// main.xml
<?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"
>
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="API키"
android:clickable="true"
/>
</LinearLayout>
// LocationShare.java
public class LocationShare extends MapActivity {
MapView mMap;
MyLocationOverlay2 mLocation;
protected boolean isRouteDisplayed() {
return false;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMap = (MapView)findViewById(R.id.mapview);
MapController mapControl = mMap.getController();
mapControl.setZoom(13);
mMap.setBuiltInZoomControls(true);
GeoPoint pt = new GeoPoint(37881311, 127729968);
mapControl.setCenter(pt);
mLocation = new MyLocationOverlay2(this, mMap);
List<Overlay> overlays = mMap.getOverlays();
overlays.add(mLocation);
mLocation.runOnFirstFix(new Runnable() {
public void run() {
mMap.getController().animateTo(mLocation.getMyLocation());
}
});
}
public void onResume() {
super.onResume();
mLocation.enableMyLocation();
mLocation.enableCompass();
}
public void onPause() {
super.onPause();
mLocation.disableMyLocation();
mLocation.disableCompass();
}
class MyLocationOverlay2 extends MyLocationOverlay {
public MyLocationOverlay2(Context context, MapView mapView) {
super(context, mapView);
}
protected boolean dispatchTap() {
Toast.makeText(LocationShare.this, "여기가 현재 위치입니다.",
Toast.LENGTH_SHORT).show();
return false;
}
}
}
반응형
'Android > 실전 TIP' 카테고리의 다른 글
앱에서 마켓 연결 (0) | 2019.03.25 |
---|---|
디바이스 정보 알아오기 (0) | 2019.03.25 |
GPS가 켜져 있는지 확인하고 안 켜져 있으면 설정창으로 이동 (0) | 2019.03.25 |
GeoPoint()로 위도, 경도 계산 (0) | 2019.03.25 |
터치 이벤트 강제 실행 (0) | 2019.03.25 |
댓글
반응형
최근에 올라온 글
- Total
- Today
- Yesterday