Display nearby places on the map

This commit is contained in:
Neslihan 2017-05-12 17:55:21 +03:00
parent c2e018ae9e
commit f6ac8fd1a5
2 changed files with 17 additions and 25 deletions

View file

@ -14,8 +14,12 @@ import butterknife.ButterKnife;
import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.services.android.telemetry.MapboxTelemetry; import com.mapbox.services.android.telemetry.MapboxTelemetry;
@ -25,10 +29,8 @@ import fr.free.nrw.commons.R;
public class NearbyMapFragment extends android.support.v4.app.Fragment { public class NearbyMapFragment extends android.support.v4.app.Fragment {
private NearbyAsyncTask nearbyAsyncTask; private NearbyAsyncTask nearbyAsyncTask;
private fr.free.nrw.commons.location.LatLng currentLocation;
@BindView(R.id.mapview) MapView mapView; private MapView mapView;
@BindView(R.id.progressBar)
ProgressBar progressBar;
public NearbyMapFragment() { public NearbyMapFragment() {
@ -37,7 +39,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
currentLocation = ((NearbyActivity)getActivity()).getLocationManager().getLatestLocation();
Mapbox.getInstance(getActivity(), Mapbox.getInstance(getActivity(),
getString(R.string.mapbox_commons_app_token)); getString(R.string.mapbox_commons_app_token));
MapboxTelemetry.getInstance().setTelemetryEnabled(false); MapboxTelemetry.getInstance().setTelemetryEnabled(false);
@ -48,9 +50,17 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_nearby_map, container, false); View view = inflater.inflate(R.layout.fragment_nearby_map, container, false);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
MapboxMapOptions options = new MapboxMapOptions()
.styleUrl(Style.OUTDOORS)
.camera(new CameraPosition.Builder()
.target(new LatLng(currentLocation.latitude, currentLocation.longitude))
.zoom(11)
.build());
// create map
mapView = new MapView(getActivity(), options);
mapView.onCreate(savedInstanceState); mapView.onCreate(savedInstanceState);
getActivity().setContentView(mapView);
setHasOptionsMenu(false); setHasOptionsMenu(false);
return view; return view;
} }
@ -97,19 +107,16 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
progressBar.setVisibility(View.VISIBLE);
} }
@Override @Override
protected void onProgressUpdate(Integer... values) { protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values); super.onProgressUpdate(values);
progressBar.setProgress(values[0]);
} }
@Override @Override
protected List<BaseMarkerOptions> doInBackground(Void... params) { protected List<BaseMarkerOptions> doInBackground(Void... params) {
return NearbyController.loadAttractionsFromLocationToBaseMarkerOptions( return NearbyController.loadAttractionsFromLocationToBaseMarkerOptions(currentLocation, getActivity()
((NearbyActivity)getActivity()).getLocationManager().getLatestLocation(), getActivity()
); );
} }

View file

@ -5,19 +5,4 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraZoom="11"
mapbox:mapbox_cameraTargetLat="50.0755"
mapbox:mapbox_cameraTargetLng="14.4378"
mapbox:mapbox_styleUrl="@string/style_mapbox_streets" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</LinearLayout> </LinearLayout>