Android การทำแผนที่บนมือถือ

การทำ Google Map บน Android สามารถทำได้ดังนี้

เตรียมคาวมพร้อมก่อนทำ Map (สำหรับผู้ใช้งานโปรแกรม eclipse)

ให้ดาว์โหลด ติดตั้ง ไฟล์ที่อยู่ใน SDK ดังต่อไปนี้ให้

- Google Play services




วิธีการหาไฟล์ Google play services




Exmaple : AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.googlemap1"
    android:versionCode="1"
    android:versionName="1.0" >
    
 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <!-- The following two permissions are not required to use
      Google Maps Android API v2, but are recommended. -->
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />
    
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        
        <activity
            android:name="com.google.googlemap1.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>
        
        <meta-data
      android:name="com.google.android.maps.v2.API_KEY"
      android:value="API_KEY"/>
        
        <meta-data
      android:name="com.google.android.gms.version"
      android:value="@integer/google_play_services_version" />
        
    </application>

</manifest>
ปล. API_KEY เราต้องทำการสร้าง Key ใหม่ขึ้นมาก่อนสามารถทำได้ดัง วิดีโอต่อไปนี้






Link ไปยัง Google APIs Console คลิก

วิธีการ import ไฟล์ google-play-services_lib





Exmaple : activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>
Exmaple : MainActivity.java
package com.google.googlemap1;

import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
ผลลัพธ์ที่ได้
























ขอขอบคุณที่มา : Google Developers

ไม่มีความคิดเห็น:

แสดงความคิดเห็น