I'm using android Mapbox SDK 4.0.0 and I cann't set center of map when location changed. I don't understand how to use MyLocationTrackingMode. Or how to recive current latitude and longitude and past them to CameraPosition. Can somebody help me, please? Thanks in advance!
package com.detores.wristmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
public class MainActivity extends AppCompatActivity {
private MapView mapView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a mapView
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(MapboxMap mapboxMap) {
// Set map style
mapboxMap.setStyleUrl(Style.MAPBOX_STREETS);
// Set the camera's starting position
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(50.0051, 36.3562)) // set the camera's center position
.zoom(12) // set the camera's zoom level
.build();
// Move the camera to that position
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
mapboxMap.setMyLocationEnabled(true);
}
});
}
#Override
public void onResume() {
super.onResume();
mapView.onResume();
}
#Override
public void onPause() {
super.onPause();
mapView.onPause();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
#Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
}
if I understand what you are trying to accomplish then this code snippet might help you get started:
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
public class MainActivity extends AppCompatActivity implements MapboxMap.OnMyLocationChangeListener {
private MapboxMap map;
private MapView mapView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(MapboxMap mapboxMap) {
map = mapboxMap;
mapboxMap.setOnMyLocationChangeListener(MainActivity.this);
mapboxMap.setMyLocationEnabled(true);
}
});
}
#Override
public void onMyLocationChange(#Nullable Location location) {
if (location != null) {
map.easeCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
}
}
// Add the mapView lifecycle to the activity's lifecycle methods
#Override
public void onResume() {
super.onResume();
mapView.onResume();
}
#Override
public void onPause() {
super.onPause();
mapView.onPause();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
#Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
Hope this helps you out!
Related
I am using MapBox to create a route between two points. I have LatLng of two points already and have successfully add Markers at source and destination point but the problem is, I am unable to create a route between them. Here is the code. I don't know where i am lacking but i have followed a tutorial but in that Tutor is creating a route between current location and the location clicked on map and he is doing stuff in onMapClicked method since i am not using that approach due to have customized point. Instead, i am doing stuff in the onMapReady method other than all the procedure is identical.
package com.devaj.googlemaps;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.devaj.googlemaps.models.TDD;
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute;
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute;
public class NavigationActivity extends AppCompatActivity implements OnMapReadyCallback{
public static final String TAG = "NavigationActivity";
private MapView mapView;
private TDD tdd;
private Point originPosition, dstPosition;
private Double originLat, originLng, dstLat, dstLng;
private LatLng originLatLng, dstLatLng;
private MapboxMap map;
private NavigationMapRoute navigationMapRoute;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, getString(R.string.access_token));
setContentView(R.layout.activity_navigation);
MapBox(savedInstanceState);
}
#Override
public void onMapReady(#NonNull MapboxMap mapboxMap) {
map = mapboxMap;
originPosition = Point.fromLngLat(originLat, originLng);
dstPosition = Point.fromLngLat(dstLat, dstLng);
MarkerOptions options = new MarkerOptions();
options.title("Source");
options.position(originLatLng);
MarkerOptions options1 = new MarkerOptions();
options1.title("Destination");
options1.position(dstLatLng);
mapboxMap.addMarker(options);
mapboxMap.addMarker(options1);
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
#Override
public void onStyleLoaded(#NonNull Style style) {
navigationMapRoute = new NavigationMapRoute(null, mapView, map, R.style.NavigationMapRoute);
getRoute(originPosition, dstPosition);
}
});
}
private void MapBox(Bundle savedInstanceState)
{
Intent i = getIntent();
tdd = (TDD) i.getSerializableExtra("tdd");
originLat = Double.parseDouble(tdd.getmSrcLat());
originLng = Double.parseDouble(tdd.getmSrcLng());
dstLat = Double.parseDouble(tdd.getmDstLat());
dstLng = Double.parseDouble(tdd.getmDstLng());
originLatLng = new LatLng(originLat, originLng);
dstLatLng = new LatLng(dstLat, dstLng);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
private void getRoute(Point origin, Point destination)
{
// CameraPosition position = new CameraPosition.Builder()
// .target(originLatLng) // Sets the new camera position
// .zoom(17) // Sets the zoom
// .bearing(180) // Rotate the camera
// .tilt(30) // Set the camera tilt
// .build(); // Creates a CameraPosition from the builder
//
// map.animateCamera(CameraUpdateFactory
// .newCameraPosition(position), 7000);
NavigationRoute.builder(NavigationActivity.this)
.accessToken(Mapbox.getAccessToken())
.origin(origin)
.destination(destination)
.build()
.getRoute(new Callback<DirectionsResponse>() {
#Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
if (response.body() == null)
{
Usable.logMessage(TAG, "No routes found, Check User and Access Token..");
return;
} else if (response.body().routes().size() == 0)
{
Usable.logMessage(TAG, "No routes found..");
return;
}
DirectionsRoute currentRoute = response.body().routes().get(0);
navigationMapRoute.addRoute(currentRoute);
}
#Override
public void onFailure(Call<DirectionsResponse> call, Throwable t) {
Log.e(TAG, "Error: "+ t.getMessage());
}
});
}
#Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
#Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
#Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
#Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
#Override
protected void onSaveInstanceState(#NonNull Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
#Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
}
You've got your lat/long order mixed up whenever you use Point.fromLngLat().
For example, dstPosition = Point.fromLngLat(dstLat, dstLng); is the wrong order.
Is there a log message in your logcat when you try the code you posted above? Search for Mbgl. Is response.body() null? Is the route size == 0? Basically, it'd be helpful if you could explain more when you say I am unable to create a route between them.
By the way, you don't have to use the Mapbox Navigation SDK for Android if you want to get a route between two points. The Mapbox Java SDK can do that.
https://docs.mapbox.com/android/java/overview/directions
https://docs.mapbox.com/android/java/examples/show-directions-on-a-map
https://docs.mapbox.com/android/java/examples/dashed-directions-line
Also, I'd move the onMapReady() stuff into the onStyleLoaded() callback.
#Override
public void onMapReady(#NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
#Override
public void onStyleLoaded(#NonNull Style style) {
map = mapboxMap;
originPosition = Point.fromLngLat(originLng, originLat);
dstPosition = Point.fromLngLat(dstLng, dstLat);
MarkerOptions options = new MarkerOptions();
options.title("Source");
options.position(originLatLng);
MarkerOptions options1 = new MarkerOptions();
options1.title("Destination");
options1.position(dstLatLng);
mapboxMap.addMarker(options);
mapboxMap.addMarker(options1);
navigationMapRoute = new NavigationMapRoute(null, mapView, map, R.style.NavigationMapRoute);
getRoute(originPosition, dstPosition);
}
});
}
helo,
i have a strange problem with app - when i use google's api for user location, the gps starts in second and goes to locate. but if i use mapbox, it takes up to 15 minutes to do what it does, then i have to turn off the screen and on again to show the gps logo at the bottom of the screen, then to turn off and on again to begin location. what could makes that. I have searched everywhere on the web for similar problems, but I found nothing. I used everything as it is described in http://www.mapbox.com for making it, and the problem still exists.
Here is the code of Main activity:
import android.arch.lifecycle.Lifecycle;
import android.location.Location;
import android.location.LocationManager;
import android.os.PersistableBundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEngineListener;
import com.mapbox.android.core.location.LocationEnginePriority;
import com.mapbox.android.core.location.LocationEngineProvider;
import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin;
import com.mapbox.mapboxsdk.plugins.locationlayer.modes.CameraMode;
import com.mapbox.mapboxsdk.plugins.locationlayer.modes.RenderMode;
import java.util.List;
public class MbooooActivity extends AppCompatActivity implements OnMapReadyCallback,
LocationEngineListener, PermissionsListener{
private MapView mapView;
private MapboxMap mbm;
private PermissionsManager permissionsManager;
private LocationEngine locationEngine;
private LocationLayerPlugin locationLayerPlugin;
private Location lokation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this,getString(R.string.toke));
setContentView(R.layout.activity_mboooo);
mapView=(MapView)findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
#Override
public void onMapReady(MapboxMap mapboxMap) {
mbm=mapboxMap;
enableLocation();
}
private void enableLocation(){
if(PermissionsManager.areLocationPermissionsGranted(this)){
initialiseLocationEngine();
initialiseLocationLayer();
}else{
permissionsManager=new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}
#SuppressWarnings("MissingPermission")
private void initialiseLocationEngine(){
locationEngine=new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.activate();
Location prevlok=locationEngine.getLastLocation();
if(prevlok!=null){
lokation=prevlok;
setCamera(prevlok);
}else{
locationEngine.addLocationEngineListener(this);
}
}
#SuppressWarnings("MissingPermission")
private void initialiseLocationLayer(){
locationLayerPlugin=new LocationLayerPlugin(mapView,mbm,locationEngine);
locationLayerPlugin.setLocationLayerEnabled(true);
locationLayerPlugin.setCameraMode(CameraMode.TRACKING);
locationLayerPlugin.setRenderMode(RenderMode.NORMAL);
Lifecycle lifecycle=getLifecycle();
lifecycle.addObserver(locationLayerPlugin);
}
private void setCamera(Location location){
mbm.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),
location.getLongitude()),16.0));
}
#SuppressWarnings("MissingPermission")
#Override
public void onConnected() {
locationEngine.requestLocationUpdates();
}
#Override
public void onLocationChanged(Location location) {
if(location!=null){
lokation=location;
setCamera(lokation);}
}
#Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
}
#Override
public void onPermissionResult(boolean granted) {
if(granted){
enableLocation();
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
permissionsManager.onRequestPermissionsResult(requestCode,permissions,grantResults);
}
#SuppressWarnings("MissingPermission")
#Override
protected void onStart() {
super.onStart();
mapView.onStart();
if(locationEngine!=null){
locationEngine.requestLocationUpdates();
locationEngine.addLocationEngineListener(this);}
}
#Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
#Override
protected void onDestroy() {
super.onDestroy();
if(locationEngine!=null){
locationEngine.removeLocationEngineListener(this);
locationEngine.removeLocationUpdates();}
}
#Override
protected void onStop() {
super.onStop();
mapView.onStop();
locationEngine.removeLocationEngineListener(this);
locationEngine.removeLocationUpdates();
}
#Override
protected void onResume() {
super.onResume();
mapView.onResume();
locationEngine.removeLocationUpdates();
locationEngine.removeLocationEngineListener(this);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
You should listen to location updates independently from last location:
private void initialiseLocationEngine(){
locationEngine=new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.activate();
locationEngine.addLocationEngineListener(this);
Location prevlok=locationEngine.getLastLocation();
if(prevlok!=null){
lokation=prevlok;
setCamera(prevlok);
}
}
Additionally you can set:
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.setInterval(0);
locationEngine.setFastestInterval(1000);
I want to upload the result from the barcode scanner to the edit text, but it is not displaying in the edit text. May I know what the problem is and how do I solve it?
This is my code
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class ScannerActivity extends AppCompatActivity {
private ZXingScannerView scannerView;
private EditText ScanBarcode;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner);
ScanBarcode = (EditText)findViewById(R.id.editscanbar);
}
public void scanCode(View view){
scannerView = new ZXingScannerView(this);
scannerView.setResultHandler(new ZXingScannerResultHandler());
setContentView(scannerView);
scannerView.startCamera();
}
#Override
public void onPause(){
super.onPause();
scannerView.stopCamera();
}
class ZXingScannerResultHandler implements ZXingScannerView.ResultHandler{
#Override
public void handleResult(Result result){
String resultCode = result.getText().toString();
ScanBarcode.setText(resultCode);
Toast.makeText(ScannerActivity.this, resultCode,
Toast.LENGTH_SHORT).show();
setContentView(R.layout.activity_scanner);
scannerView.stopCamera();
}
}
}
I've changed it and there is still nothing showing up in the edit text
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class ScannerActivity extends AppCompatActivity implements
ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
private EditText ScanBarcode;
#Override
public void onCreate(Bundle State) {
super.onCreate(State);
mScannerView = new ZXingScannerView(this);
setContentView(R.layout.activity_scanner);
ScanBarcode = (EditText)findViewById(R.id.editscanbar);
}
public void scanCode(View view){
mScannerView.setResultHandler(this);
setContentView(mScannerView);
mScannerView.startCamera();
}
#Override
public void onResume(){
super.onResume();
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
#Override
public void onPause(){
super.onPause();
mScannerView.stopCamera();
}
#Override
public void handleResult(Result rawResult){
ScanBarcode.setText(rawResult.getText());
setContentView(R.layout.activity_scanner);
mScannerView.stopCamera();
}
}
you should implement the ResultHandler in your Activity, override the callback method and there set the result of the scan in your EditText, example:
public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
private EditText editText;
#Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view
setContentView(mScannerView); // Set the scanner view as the content view
EditText editText = (EditText)findViewById(R.id.myedittext);
}
#Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
#Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
#Override
public void handleResult(Result rawResult) {
// Do something with the result here
editText.setText(rawResult.getText());
Log.v(TAG, rawResult.getText()); // Prints scan results
Log.v(TAG, rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)
// If you would like to resume scanning, call this method below:
mScannerView.resumeCameraPreview(this);
}
}
Hope it helps!
I am trying to write code on button click in a fragment,but the buttons are not working. The buttons are set to increase and decrease the value of textview (rangeText).
I have implemented OnClickListener to my fragment.
I want to know where is the mistake.
package com.neoresearch.bookmyspace;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
/**
* A fragment that launches other parts of the demo application.
*/
public class ParkingFinderMapFragment extends Fragment implements View.OnClickListener {
LinearLayout layoutOfPopup;
PopupWindow popupMessage;
Button popupButton, insidePopupButton, searchButton, rangeIncrement, rangeDecrement;
TextView rangeText;
TextView name, contact, address, availability;
AutoCompleteTextView searchText;
LatLng latLng;
MarkerOptions markerOptions;
MapView mMapView;
GoogleMap googleMap;
private EditText editText;
String string;
private View v;
int range;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
}
#Override
public void onDetach() {
super.onDetach();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflat and return the layout
v = inflater.inflate(R.layout.fragment_parking_finder_map, container,
false);
searchText = (AutoCompleteTextView) v.findViewById(R.id.search_on_map);
searchButton = (Button) v.findViewById(R.id.button_search);
rangeIncrement = (Button) v.findViewById(R.id.range_increment);
rangeDecrement = (Button) v.findViewById(R.id.range_decrament);
rangeText = (TextView) v.findViewById(R.id.range_select);
mMapView = (MapView) v.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();
}
googleMap = mMapView.getMap();
// latitude and longitude
double latitude = 17.385044;
double longitude = 78.486671;
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("Hello Maps");
// Changing marker icon
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
// adding marker
googleMap.addMarker(marker);
LatLng indore = new LatLng(22.7000, 75.9000);
final MarkerOptions marker2 = new MarkerOptions().position(indore).title("Indore");
googleMap.addMarker(marker2);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(22.7000, 75.9000)).zoom(8).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
// Perform any camera updates here
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
PopupOnMap pop = new PopupOnMap(getActivity());
pop.show();
pop.setName("prafull", marker.getTitle(), "8269564260");
return false;
}
});
searchButton.setOnClickListener(this);
rangeDecrement.setOnClickListener(this);//these are my buttons
rangeIncrement.setOnClickListener(this);
return v;
}
#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();
}
//here is onclick listeners
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_search:
break;
case R.id.range_increment:
range = Integer.parseInt(rangeText.getText().toString());
if (range > 0 && range < 20) {
range = range++;
}
rangeText.setText(range);
break;
case R.id.range_decrament:
range = Integer.parseInt(rangeText.getText().toString());
if (range > 0 && range < 20) {
range = range--;
}
rangeText.setText(range);
break;
}
}
}
Make the following changes to your onClick() method :
case R.id.range_increment:
range = Integer.parseInt(rangeText.getText().toString());
if (range > 0 && range < 20) {
range = range++;
}
rangeText.setText(String.valueOf(range));
break;
case R.id.range_decrament:
range = Integer.parseInt(rangeText.getText().toString());
if (range > 0 && range < 20) {
range = range--;
}
rangeText.setText(String.valueOf(range));
break;
I created RoboSherlockMapActivity.java
import roboguice.RoboGuice;
import roboguice.activity.event.OnActivityResultEvent;
import roboguice.activity.event.OnConfigurationChangedEvent;
import roboguice.activity.event.OnContentChangedEvent;
import roboguice.activity.event.OnCreateEvent;
import roboguice.activity.event.OnDestroyEvent;
import roboguice.activity.event.OnNewIntentEvent;
import roboguice.activity.event.OnPauseEvent;
import roboguice.activity.event.OnRestartEvent;
import roboguice.activity.event.OnResumeEvent;
import roboguice.activity.event.OnStartEvent;
import roboguice.activity.event.OnStopEvent;
import roboguice.event.EventManager;
import roboguice.inject.ContentViewListener;
import roboguice.inject.RoboInjector;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import com.actionbarsherlock.view.Menu;
import com.google.android.maps.MapActivity;
import com.google.inject.Inject;
public class RoboSherlockMapActivity extends MapActivity{
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
protected EventManager eventManager;
#Inject ContentViewListener ignored; // BUG find a better place to put this
#Override
protected void onCreate(Bundle savedInstanceState) {
final RoboInjector injector = RoboGuice.getInjector(this);
eventManager = injector.getInstance(EventManager.class);
injector.injectMembersWithoutViews(this);
super.onCreate(savedInstanceState);
eventManager.fire(new OnCreateEvent(savedInstanceState));
}
#Override
protected void onRestart() {
super.onRestart();
eventManager.fire(new OnRestartEvent());
}
#Override
protected void onStart() {
super.onStart();
eventManager.fire(new OnStartEvent());
}
#Override
protected void onResume() {
super.onResume();
eventManager.fire(new OnResumeEvent());
}
#Override
protected void onPause() {
super.onPause();
eventManager.fire(new OnPauseEvent());
}
#Override
public void onNewIntent( Intent intent ) {
super.onNewIntent(intent);
eventManager.fire(new OnNewIntentEvent());
}
#Override
protected void onStop() {
try {
eventManager.fire(new OnStopEvent());
} finally {
super.onStop();
}
}
#Override
protected void onDestroy() {
try {
eventManager.fire(new OnDestroyEvent());
} finally {
try {
RoboGuice.destroyInjector(this);
} finally {
super.onDestroy();
}
}
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
final Configuration currentConfig = getResources().getConfiguration();
super.onConfigurationChanged(newConfig);
eventManager.fire(new OnConfigurationChangedEvent(currentConfig, newConfig));
}
#Override
public void onContentChanged() {
super.onContentChanged();
RoboGuice.getInjector(this).injectViewMembers(this);
eventManager.fire(new OnContentChangedEvent());
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
eventManager.fire(new OnActivityResultEvent(requestCode, resultCode, data));
}
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
return false;
}
}
I inherited this and not MapActivity. Still the Action bar Sherlock doesn't show up. What might be going wrong here?
To use ActionBarSherlock with MapActivity you have to extend your Activity class from
com.actionbarsherlock.app.SherlockMapActivity which you can download from ActionBarSherlock-Plugin-Maps.
This class is a plugin for ActionBarSherlock to support MapActivity link to mentioned github project you can also find in ActionBarSherlock download section.