2012-01-20 37 views
2

私はGoogleマップを表示するアプリケーションを作っていますが、問題は地図/衛星/何も表示していないということです。それは単なる大きな灰色の領域です。私はライブラリとGoogleマップのAPIキーだけでなく、インターネットのアクセス許可を追加しました。どうすればこの問題を解決できますか?私が使用していますコード:Googleマップは表示されません

MapTabView.java:

public class MapTabView extends MapActivity implements OnClickListener { 
public static final String TAG = "GoogleMapsActivity"; 
private MapView mapView; 
private LocationManager locationManager; 
Geocoder geocoder; 
Location location; 
LocationListener locationListener; 
CountDownTimer locationtimer; 
MapController mapController; 
MapOverlay mapOverlay = new MapOverlay(); 
EditText SearchInput; 
Button SearchButton; 

@Override 
protected void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.main); 
    onTabStart(); 
    initComponents(); 
    mapView.setBuiltInZoomControls(true); 
    mapView.setSatellite(true); 
    mapController = mapView.getController(); 
    mapController.setZoom(16); 
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 
    if (locationManager == null) { 
     Toast.makeText(MapTabView.this, 
       "Location Manager Not Available", Toast.LENGTH_SHORT) 
       .show(); 
     return; 
    } 
    location = locationManager 
      .getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    if (location == null) 
     location = locationManager 
       .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
    if (location != null) { 
     double lat = location.getLatitude(); 
     double lng = location.getLongitude(); 
     Toast.makeText(MapTabView.this, 
       "Location Are" + lat + ":" + lng, Toast.LENGTH_SHORT) 
       .show(); 
     GeoPoint point = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); 
     mapController.animateTo(point, new Message()); 
     mapOverlay.setPointToDraw(point); 
     List<Overlay> listOfOverlays = mapView.getOverlays(); 
     listOfOverlays.clear(); 
     listOfOverlays.add(mapOverlay); 
    } 
    locationListener = new LocationListener() { 
     @Override 
     public void onStatusChanged(String arg0, int arg1, Bundle arg2) { 
     } 

     @Override 
     public void onProviderEnabled(String arg0) { 
     } 

     @Override 
     public void onProviderDisabled(String arg0) { 
     } 

     @Override 
     public void onLocationChanged(Location l) { 
      location = l; 
      locationManager.removeUpdates(this); 
      if (l.getLatitude() == 0 || l.getLongitude() == 0) { 
      } else { 
       double lat = l.getLatitude(); 
       double lng = l.getLongitude(); 
       Toast.makeText(MapTabView.this, 
         "Location Are" + lat + ":" + lng, 
         Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }; 
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) 
     locationManager.requestLocationUpdates(
       LocationManager.GPS_PROVIDER, 1000, 10f, locationListener); 
    locationManager.requestLocationUpdates(
      LocationManager.NETWORK_PROVIDER, 1000, 10f, locationListener); 
    locationtimer = new CountDownTimer(30000, 5000) { 
     @Override 
     public void onTick(long millisUntilFinished) { 
      if (location != null) 
       locationtimer.cancel(); 
     } 

     @Override 
     public void onFinish() { 
      if (location == null) { 
      } 
     } 
    }; 
    locationtimer.start(); 
} 

private void onTabStart() { 
    // TODO Auto-generated method stub 
    TabHost tabHost=(TabHost)findViewById(R.id.tabHost); 
    tabHost.setup(); 

    TabSpec spec2=tabHost.newTabSpec("Tab 1"); 
    spec2.setIndicator("Map"); 
    spec2.setContent(R.id.tab1); 

    TabSpec spec3=tabHost.newTabSpec("Tab 2"); 
    spec3.setIndicator("Search"); 
    spec3.setContent(R.id.tab2); 

    tabHost.addTab(spec2); 
    tabHost.addTab(spec3); 
    tabHost.setCurrentTab(1); 
    SearchButton = (Button)findViewById(R.id.SearchButton); 
    SearchButton.setOnClickListener(this); 

} 
public void onClick(View src) { 
    switch(src.getId()) { 
    case R.id.SearchButton: 
     SearchInput = (EditText)findViewById(R.id.SearchInput); 
     String SearchInputText = ""; 
     SearchInputText = SearchInput.getText().toString(); 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0q=" + SearchInputText)); 
     startActivity(intent); 
     break; 
    } 
} 

public MapView getMapView() { 
    return this.mapView; 
} 

private void initComponents() { 
    mapView = (MapView) findViewById(R.id.mapview); 
} 

@Override 
protected boolean isRouteDisplayed() { 
    return false; 
} 

class MapOverlay extends Overlay { 
    private GeoPoint pointToDraw; 

    public void setPointToDraw(GeoPoint point) { 
     pointToDraw = point; 
    } 

    public GeoPoint getPointToDraw() { 
     return pointToDraw; 
    } 

    @Override 
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, 
      long when) { 
     super.draw(canvas, mapView, shadow); 

     Point screenPts = new Point(); 
     mapView.getProjection().toPixels(pointToDraw, screenPts); 

     Bitmap bmp = BitmapFactory.decodeResource(getResources(), 
       R.drawable.pinblue); 
     canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 24, null); 
     return true; 
    } 
} 

} 

Main.xml:

<?xml version="1.0" encoding="utf-8"?> 

<TabHost android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/tabHost" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<TabWidget 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@android:id/tabs" 
/> 
<FrameLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@android:id/tabcontent" 
> 



<LinearLayout 
    android:id="@+id/tab1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:paddingTop="60px" > 


    <TextView 
     android:id="@+id/txt2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Map" /> 

    <com.google.android.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1.12" 
     android:apiKey="09AeOreJeLtH579e3G74Icfle664gxXhbfh1O7Q" 
     android:clickable="true" > 
    </com.google.android.maps.MapView> 
</LinearLayout> 


    <LinearLayout 
     android:id="@+id/tab2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:paddingTop="60px" > 

<TextView 
    android:id="@+id/txt3" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Search for gokart tracks" /> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <EditText 
     android:id="@+id/SearchInput" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="10.05" > 

     <requestFocus /> 
    </EditText> 

    <Button 
     android:id="@+id/SearchButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@android:string/search_go" /> 
</LinearLayout> 


<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/GoogleMapOpenText" /> 

</LinearLayout> 

</FrameLayout> 

</TabHost> 
+0

関連コードを入力してください。 –

答えて

1

私は自分の携帯電話

2

たびに署名APKをインストールするまで、私は同じ問題を持っていましたGoogleマップは私には表示されませんが、最終的にはこれらの問題の1つになります:

  1. プロジェクトの間違ったキーストアからハッシュ、つまりAPIキーを生成しました。私は1つのキーストアでこのアプリケーションに署名し、別のキーストアでハッシュを生成しました。
  2. 私はAPIキーを含んでいません
  3. 私はAPKに署名していないので、それをテストするために電話機にインストールしました。署名されたAPKでなければなりません。そうでないと動作しません。

また、テストする電話機は指定していません。エミュレータでは動作しないと思われます。電話機でなければなりません。

+0

私はほとんど常に私のLG Optimus 2X P990で実行中のデバッグをしています。アンドロイド2.3.7 Cyanogenmod 7 – Erik

1

参照が正しいことを確認してください。

<script> src="http://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript" </script> 

あなたが含める必要があります。あなたのコードが何であるかを確認しますが、私はこのように地雷をしない:

function init() { 
     var mapOptions = { 
      //include all of the map's information here 
      center: new google.maps.LatLng(lat_value,lng_value), 
      zoom: 10, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
     map = new google.maps.Map(document.getElementById(mapHTMLLocationString), mapOptions); 
    } 

他の利用可能なマップのオプションを表示するには、Googleマップreferenceを参照してください。私はcentermapTypeIdが地図を取得するために唯一必要なオプションだと思います。

+0

OPは、Android API用のGoogle Maps APIを指しています。javascriptではありません。 –

関連する問題