2016-09-20 5 views
1

구글 맵스 유틸리티 라이브러리를 사용하여 안드로이드에 히트 맵 포인트를 표시하려고합니다. 아무 것도지도에 표시되지 않습니다. 나는 내가 다른 것을 필요로하는지 모른다. 예를 들었지만 내 경우 엔 효과가 없다. 나는 파편을 사용하고있다.히트 맵이 조각에 표시되지 않습니다.

public class MapFragment extends Fragment { 


MapView mMapView; 
private GoogleMap googleMap; 
private HeatmapTileProvider mProvider; 
protected LatLng mCenterLocation = new LatLng(39.7392, -104.9903); 

public MapFragment() { 
    // Required empty public constructor 
} 


@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    View rootView = inflater.inflate(R.layout.fragment_map, container, false); 

    mMapView = (MapView) rootView.findViewById(R.id.mapView); 
    mMapView.onCreate(savedInstanceState); 
    mMapView.onResume(); // needed to get the map to display immediately 
    try { 
     MapsInitializer.initialize(getActivity().getApplicationContext()); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    mMapView.getMapAsync(new OnMapReadyCallback() { 
     @Override 
     public void onMapReady(GoogleMap mMap) { 
      googleMap = mMap; 

      // For showing a move to my location button 
      if (ActivityCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
       // TODO: Consider calling 
       // ActivityCompat#requestPermissions 
       // here to request the missing permissions, and then overriding 
       // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
       //           int[] grantResults) 
       // to handle the case where the user grants the permission. See the documentation 
       // for ActivityCompat#requestPermissions for more details. 
       return; 
      } 
      googleMap.setMyLocationEnabled(true); 

      // For dropping a marker at a point on the Map 
      LatLng colorado = new LatLng(39.7392, -104.9903); 
      googleMap.addMarker(new MarkerOptions().position(colorado).title("Marker Title").snippet("Marker Description")); 

      // For zooming automatically to the location of the marker 
      CameraPosition cameraPosition = new CameraPosition.Builder().target(colorado).zoom(12).build(); 
      googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 

      addHeatMap(); 

     } 
    }); 




    return rootView; 
} 


public void addHeatMap(){ 
    ArrayList<LatLng> locations = generateLocations(); 
    mProvider = new HeatmapTileProvider.Builder().data(locations).build(); 
    mProvider.setRadius(HeatmapTileProvider.DEFAULT_RADIUS); 
    googleMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider)); 
} 

private ArrayList<LatLng> generateLocations() { 
    ArrayList<LatLng> locations = new ArrayList<LatLng>(); 
    double lat; 
    double lng; 
    Random generator = new Random(); 
    for (int i = 0; i < 1000; i++) { 
     lat = generator.nextDouble()/3; 
     lng = generator.nextDouble()/3; 
     if (generator.nextBoolean()) { 
      lat = -lat; 
     } 
     if (generator.nextBoolean()) { 
      lng = -lng; 
     } 
     locations.add(new LatLng(mCenterLocation.latitude + lat, mCenterLocation.longitude + lng)); 
    } 

    return locations; 
} 

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

@Override 
public void onPause() { 
    super.onPause(); 
    mMapView.onPause(); 
} 

@Override 
public void onDestroy() { 
    super.onDestroy(); 
    mMapView.onDestroy(); 
} 

@Override 
public void onLowMemory() { 
    super.onLowMemory(); 
    mMapView.onLowMemory(); 
} 

} 

답변

0

Heatmaps guide을 확인해도 문제가 없습니다. clearTileCache()으로 전화하여 API reference에 표시된 후 setRadius 뒤에 전화해야합니다.

+0

답변을 주셔서 감사합니다. 마커도 표시되지 않고 카메라 위치가 작동하지 않는 것으로 나타났습니다.지도 설정에 문제가 있다고 생각합니다. 뭐가 잘못 됐는지 몰라. –