2015-04-21 19 views
0

我一直在製作一個簡單的演示應用程序來測試Google Maps API上的羣集;然而,似乎沒有任何東西顯示出來。我不知道是什麼原因造成的,因爲我從谷歌網站逐字複製了代碼。試圖設置一個非常簡單的Android Google Google地圖,但沒有任何顯示

由於提前,

雅各

package com.example.toshiba.jsonmap; 

import android.app.Activity; 
import android.os.Bundle; 

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.maps.android.clustering.ClusterItem; 
import com.google.maps.android.clustering.ClusterManager; 

public class MainActivity extends Activity { 
    GoogleMap map; 
    ClusterManager mClusterManager; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     MapFragment mapFragment = (MapFragment) getFragmentManager() 
       .findFragmentById(R.id.map); 
     GoogleMap map = mapFragment.getMap(); 
    } 
    private void setUpClusterer() { 
     // Declare a variable for the cluster manager. 


     // Position the map. 
     map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10)); 

     // Initialize the manager with the context and the map. 
     // (Activity extends context, so we can pass 'this' in the constructor.) 
     mClusterManager = new ClusterManager<MyItem>(this, map); 

     // Point the map's listeners at the listeners implemented by the cluster 
     // manager. 
     map.setOnCameraChangeListener(mClusterManager); 
     map.setOnMarkerClickListener(mClusterManager); 

     // Add cluster items (markers) to the cluster manager. 
     addItems(); 
    } 

    private void addItems() { 

     // Set some lat/lng coordinates to start with. 
     double lat = 51.5145160; 
     double lng = -0.1270060; 

     // Add ten cluster items in close proximity, for purposes of this example. 
     for (int i = 0; i < 10; i++) { 
      double offset = i/60d; 
      lat = lat + offset; 
      lng = lng + offset; 
      MyItem offsetItem = new MyItem(lat, lng); 
      mClusterManager.addItem(offsetItem); 
     } 
    } 
} 


class MyItem implements ClusterItem { 
    private final LatLng mPosition; 

    public MyItem(double lat, double lng) { 
     mPosition = new LatLng(lat, lng); 
    } 

    @Override 
    public LatLng getPosition() { 
     return mPosition; 
    } 
} 

回答

1

雖然聲明setUpClusterer,你永遠不調用它。