android studio google map v2 (2)

2015. 10. 29. 22:33Mobile/Android



반응형

android studio google map v2 (2)

이번에는 스튜디오에서  발급받은 API키로  맵을 실행 시켜보겠습니다



발급방법 API키는 아래글 참고~

http://ggari.tistory.com/451



documentation 은 아래 전체적인고 참고 

https://developers.google.com/maps/documentation/android-api/



1. File -> Project Structure 를 클릭 해주세요




2. app ->Dependencies  -> + 버튼 -> Library dependency 를 클릭해주세요(스샷은 없음)



3.  play-services 를 선택 후 OK 클릭






MainActivity.java


package com.example.ggarigooglemaptest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends AppCompatActivity {
private GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

LatLng KANGNAM = new LatLng(37.5172360, 127.0473250);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.addMarker(new MarkerOptions().position(KANGNAM).title("ggari").snippet("hello"));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(KANGNAM, 15));
}
}


activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"
/>

</RelativeLayout>













AndroidManifest.xml - 빨간부분 추가


<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.ggarigooglemaptest"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA3h0GC3_MdYeVHs9D3h1h67xv3FgqQfn4"/>

<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

<!--googlemap permission s -->
<permission
android:name="com.trosvision.store02.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.trosvision.store02.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<!--googlemap permission e -->

</manifest>






잘나오네요~ 












끝~


반응형

'Mobile > Android' 카테고리의 다른 글

안드로이드 6.0 마시멜로 업데이트 및 개발자 정보  (0) 2015.11.01
multidex android studio  (0) 2015.10.30
android studio google map v2 (1)  (0) 2015.10.29
Android ORM greenDAO  (0) 2015.10.28
android facebook 연동  (0) 2015.10.22