2016-04-22 9 views
-2

私はAPIキーを持っていますが、まだ私のプロジェクトでGoogleマップを開くことができません。私の要件は、私はGoogleマップを使用して私のアプリで現在の場所と近くの病院の詳細を取得する必要があり、私はその距離に沿って昇順にその場所に近い病院のリストが欲しいです。私の病院をクリックした後、現在の場所から特定の病院までの道のりを見ることができます。以下のUI部分を見つけてくださいenter image description here私を助けてください。Googleマップのマップイベントを使用できません。私はAPIキーを持っていますが、

+0

あれば、あなたがあなたのコードとスタックトレースを試みているものを私たちに表示します。 –

答えて

0

まずはお聞かせください。あなたは今まで何をしていたのですか?あなたのコーディングに基づいて、どの開発者もあなたを提案することができます。

public class MainActivity extends Activity { 

private GoogleMap googleMap; 

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

    try { 
     initilizeMap(); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

} 

private void initilizeMap() { 
    if (googleMap == null) { 
     googleMap = ((MapFragment) getFragmentManager().findFragmentById(
       R.id.map)).getMap(); 

     if (googleMap == null) { 
      Toast.makeText(getApplicationContext(), 
        "Sorry! unable to create maps", Toast.LENGTH_SHORT) 
        .show(); 
     } 
    } 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    initilizeMap(); 
} 

}

かつ最も重要な定義の任意の方法は、あなたがMainActivityでマップをgoogleの初期化

。これに従ってください

<RelativeLayout 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" > 


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

</RelativeLayout> 

のようなXMLを定義してください。マニフェストファイルをすべての権限で適切に

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

<permission 
    android:name="packagename.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature" /> 

<uses-permission android:name="packagename.permission.MAPS_RECEIVE" /> 

<uses-sdk 
    android:minSdkVersion="16" 
    android:targetSdkVersion="23" /> 

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

<!-- Required OpenGL ES 2.0. for Maps V2 --> 
<uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name"> 
    <activity 
     android:name="packagename.MainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppBaseTheme" 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

    <!-- Goolge API Key --> 
    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIzaSyBZMlkOv4sj-M5JO9p6wksdax4TEjDVLgo" /> 
</application> 

+0

また、マニフェストにタグ kitkat

関連する問題