2015-01-12 3 views
5

アンドロイドアプリケーションでマップビューを追加しました。マニフェストに正しい設定を使用しましたが、今は問題に直面しています。私が私の地図を持っているところに行くと、キャンバスだけが表示されますが、地図は表示されません。私はそれに触れるだけで、それは読み込みを開始します。それでも、完全にはロードされません。一定のレベルまでしかロードされません。しかし、それでも私はズームインまたはズームアウトできないし、地図を移動することもできない。これには解決策がありますか?私は何か間違ったことをした?マップビューに触れない限り、Android MapViewはロードされません

マイコード

  MapView mapView; 
      GoogleMap map; 





      mapView = (MapView)view.findViewById(R.id.map); 
      Bundle savedInstanceState = null; 
      mapView.onCreate(savedInstanceState); 

       // Gets to GoogleMap from the MapView and does initialization stuff 
       map = mapView.getMap(); 
       map.getUiSettings().setMyLocationButtonEnabled(false); 
       map.setMyLocationEnabled(true); 

       MapsInitializer.initialize(activity); 

       double lat; 
       double lon; 

       lat = Double.parseDouble(theaterDetail.getLatitude()); 
       lon = Double.parseDouble(theaterDetail.getLongitude()); 

       // Updates the location and zoom of the MapView 
       map.addMarker(new MarkerOptions().position(
         new LatLng(lat, lon)).title(theaterDetail.getAddress())); 

       final LatLng THEATER_POSITION = new LatLng(lat, lon); 

       CameraPosition cameraPosition = new CameraPosition.Builder() 
         .target(THEATER_POSITION) // Sets the center of the map to 
                // THEATER_POSITION 
         .zoom(10) // Sets the zoom 
         .bearing(360) // Sets the orientation of the camera to east 
         .tilt(30) // Sets the tilt of the camera to 30 degrees 
         .build(); // Creates a CameraPosition from the builder 
         map.animateCamera(CameraUpdateFactory 
         .newCameraPosition(cameraPosition)); 

XML

<com.google.android.gms.maps.MapView 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1"/> 

マニフェスト

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

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="18" /> 

    <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"/> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" 
     /> 

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

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






    <application 
     android:name="com.***.***.service.CommonVariable" 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppBaseTheme" 
     android:hardwareAccelerated="true" > 

     <meta-data 
    android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" /> 


     <!-- <uses-library android:name="com.google.android.maps" /> --> 

     <activity 
      android:name="com.***.***.MainActivity" 
      android:label="@string/app_name" 
      android:theme="@style/Theme.Sherlock.Light.DarkActionBar" 
      android:windowSoftInputMode="adjustPan" 
      android:hardwareAccelerated="true"> 
     </activity> 

     <activity 
      android:name="com.***.***.Map" 
      android:label="@string/app_name" 
      android:theme="@style/Theme.Sherlock.Light.DarkActionBar" ></activity> 

     <activity 
      android:name="com.***.***.WelcomeActivity" 
      android:label="@string/app_name" 
      android:theme="@style/Theme.Sherlock.NoActionBar" 
      android:hardwareAccelerated="true" > 
      <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="*********************" /> 


    </application> 

</manifest> 
+0

上記のコードは、どのクラスの関数で作成していますか?なぜこの関数をmapView.onCreate(savedInstanceState);と呼びますか? – EagleEye

+0

私のmapviewコードはasyncTaskの中に置かれ、私はこれをこのように呼びます。 \t \t場合(ページ== Element.THEATER_DETAIL.getType()){ \t \t \tビュー= inflater.inflate(R.layout.filmhall、容器、偽)。 \t \t \tシアターシアター=(シアター)item.get(位置); \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t新しい背景((theater.getTheaterId())、ビュー).execute(); \t \t \t \t \t – CraZyDroiD

+0

@EagleEye解決策はありますか? – CraZyDroiD

答えて

0

Javaファイル

package com.dilip.googlemapsv2; 

import com.google.android.gms.common.GooglePlayServicesUtil; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapFragment; 

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.widget.Toast; 

public class MainActivity extends FragmentActivity { 

    // Google Map 
    private GoogleMap googleMap; 


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

     try { 
      // Loading map 
      initilizeMap(); 

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



    /** 
    * function to load map. If map is not created it will create it for you 
    * */ 
    private void initilizeMap() { 
     if (googleMap == null) { 
      //googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap(); 
      googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap(); 

      // check if map is created successfully or not 
      if (googleMap == null) { 
       Toast.makeText(getApplicationContext(),"Sorry! unable to create maps", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.getApplicationContext()); 
     initilizeMap(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 

XMLページコード

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 


    <fragment 
     android:id="@+id/map" 

     android:name="com.google.android.gms.maps.MapFragment"  
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 



</RelativeLayout> 

Mainfestファイル

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.dilip.googlemapsv2" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <permission 
     android:name="com.dilip.googlemapsv2.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

    <uses-sdk 
     android:minSdkVersion="14" 
     android:targetSdkVersion="20" /> 
    <uses-permission android:name="com.dilip.googlemapsv2.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 



      <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=".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> 

     <!-- Goolge API Key --> 
     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />    /* Added Bi Dilip */ 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
    </application> 

</manifest> 
+1

あなたは何をしたのか説明できますか? – CraZyDroiD

+0

上記のコードは正常に動作しています... ur errorは私にlogcatを表示してください... – Dilip

+0

MapFragmentを使用しています。私はMapViewをやっています – CraZyDroiD

19

これは古い質問ですが、私は私のために働いていたものをここに提供しています。このソリューションが動作するのは、onResume()ハンドラをオーバーライドするためです。 mapViewを使用している場合は、onResume()ハンドラからmapView.onResume()を呼び出す必要があります。例:

@Override 
public void onResume() { 
    mMapView.onResume(); 
    super.onResume(); 
} 
+0

あなたは私のヒーローです!これはまさに私が上記の問題に必要な解決策でした! – Burkely91

+2

まさに私が探していたものです。また、onPause()メソッドとonLowMemory()メソッドにフックする必要があることにも注意してください。ありがとう! – Grime

+0

あなたは私を助けてくれました。これが問題を解決しました!ヒーロー。 –

関連する問題