[android] Implement UserLocationView
Draws animated and synced GPS marker. Inlcudes direction arrow and accuracy ring. Fade out the compass after a delay when reset to north. Lots of other performance and memory improvements. add OnMyLocationChangeListener Move FAB with snackbar Fix getMetersPerPixelAtLatitude Fix some incorrect annotations Fixes #2668 Fixes #2411 Fixes #2678 Fixes #2675 Fixes #2566 Fixes #2549 Fixes #2692 Fixes #2572
This commit is contained in:
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
@@ -42,7 +43,7 @@ public class InfoWindowAdapterActivity extends AppCompatActivity {
|
||||
private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);
|
||||
|
||||
@Override
|
||||
public View getInfoWindow(Marker marker) {
|
||||
public View getInfoWindow(@NonNull Marker marker) {
|
||||
TextView textView = new TextView(InfoWindowAdapterActivity.this);
|
||||
textView.setText(marker.getTitle());
|
||||
textView.setTextColor(Color.WHITE);
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
@@ -63,6 +65,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private TextView mFpsTextView;
|
||||
private int mSelectedStyle = R.id.actionStyleMapboxStreets;
|
||||
private NavigationView mNavigationView;
|
||||
private CoordinatorLayout mCoordinatorLayout;
|
||||
|
||||
// Used for GPS
|
||||
private FloatingActionButton mLocationFAB;
|
||||
@@ -102,6 +105,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
setupDrawerContent(mNavigationView);
|
||||
}
|
||||
|
||||
mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.mainMapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
@@ -110,7 +115,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
mMapView.setOnMapLongClickListener(new MapView.OnMapLongClickListener() {
|
||||
@Override
|
||||
public void onMapLongClick(LatLng point) {
|
||||
public void onMapLongClick(@NonNull LatLng point) {
|
||||
mMapView.addMarker(new MarkerOptions()
|
||||
.position(point)
|
||||
.title("Dropped Pin")
|
||||
@@ -122,21 +127,41 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
mMapView.setOnMapClickListener(new MapView.OnMapClickListener() {
|
||||
@Override
|
||||
public void onMapClick(LatLng point) {
|
||||
public void onMapClick(@NonNull LatLng point) {
|
||||
String location = latLngFormatter.format(point.getLatitude()) + ", " +
|
||||
latLngFormatter.format(point.getLongitude());
|
||||
Snackbar.make(findViewById(android.R.id.content), "Map Click Listener " + location, Snackbar.LENGTH_SHORT).show();
|
||||
Snackbar.make(mCoordinatorLayout, "Map Click Listener " + location, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
mMapView.setOnMarkerClickListener(new MapView.OnMarkerClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClick(Marker marker) {
|
||||
Snackbar.make(findViewById(android.R.id.content), "Custom Marker Click Listener", Snackbar.LENGTH_SHORT).show();
|
||||
public boolean onMarkerClick(@NonNull Marker marker) {
|
||||
Snackbar.make(mCoordinatorLayout, "Custom Marker Click Listener", Snackbar.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mMapView.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
|
||||
@Override
|
||||
public void onMyLocationChange(@Nullable Location location) {
|
||||
String desc = "Loc Chg: ";
|
||||
boolean noInfo = true;
|
||||
if (location.hasSpeed()) {
|
||||
desc += String.format("Spd = %.1f km/h ", location.getSpeed() * 3.6f);
|
||||
noInfo = false;
|
||||
}
|
||||
if (location.hasAltitude()) {
|
||||
desc += String.format("Alt = %.0f m ", location.getAltitude());
|
||||
noInfo = false;
|
||||
}
|
||||
if (noInfo) {
|
||||
desc += "No extra info";
|
||||
}
|
||||
Snackbar.make(mCoordinatorLayout, desc, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
mFpsTextView = (TextView) findViewById(R.id.view_fps);
|
||||
mFpsTextView.setText("");
|
||||
|
||||
@@ -149,7 +174,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (mMapView.isMyLocationEnabled()) {
|
||||
Location location = mMapView.getMyLocation();
|
||||
if (location != null) {
|
||||
mMapView.setZoomLevel(8);
|
||||
mMapView.setZoomLevel(18);
|
||||
mMapView.setCenterCoordinate(new LatLng(location));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,33 +27,35 @@
|
||||
android:layout_below="@+id/toolbar">
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:id="@+id/coordinator_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.mapbox.mapboxsdk.views.MapView
|
||||
android:id="@+id/mainMapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
<com.mapbox.mapboxsdk.views.MapView
|
||||
android:id="@+id/mainMapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/view_fps"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="@string/label_fps"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||
<TextView
|
||||
android:id="@+id/view_fps"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="@string/label_fps"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/locationFAB"
|
||||
android:src="@drawable/ic_my_location_black_24dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
app:backgroundTint="@color/white"
|
||||
/>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/locationFAB"
|
||||
android:src="@drawable/ic_my_location_black_24dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
app:backgroundTint="@color/white"
|
||||
/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
Reference in New Issue
Block a user