I used a recreate method of activity lifecycle in my onActivityResult so that the activity refresh
everything works fine in my activity but the google map shows a white screen !!!
and when i move to another activity and come back to this activity the map is load and its works fine !! Thanks for the help in advance
recreate();
And i have the map fragment in the layout,I used workaroundMapFragment to customize map to have a scroll on map
<fragment
android:id="#+id/view_receipt_map"
android:name="com.receiptmatch.android.utils.WorkaroundMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
public class WorkaroundMapFragment extends SupportMapFragment {
private OnTouchListener mListener;
View layout;
#Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle savedInstance) {
layout = super.onCreateView(layoutInflater, viewGroup, savedInstance);
TouchableWrapper frameLayout = new TouchableWrapper(getActivity());
frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));
((ViewGroup) layout).addView(frameLayout,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return layout;
}
public WorkaroundMapFragment setListener(OnTouchListener listener) {
mListener = listener;
return this;
}
public interface OnTouchListener {
void onTouch();
}
public class TouchableWrapper extends FrameLayout {
public TouchableWrapper(Context context) {
super(context);
}
#Override
public boolean dispatchTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mListener.onTouch();
break;
case MotionEvent.ACTION_UP:
mListener.onTouch();
break;
}
return super.dispatchTouchEvent(event);
}
}
}
In my Activity
private WorkaroundMapFragment supportMapFragment;
private GoogleMap mMap;
mMap = ((WorkaroundMapFragment) getSupportFragmentManager().findFragmentById(R.id.view_receipt_map)).getMap();
supportMapFragment = ((WorkaroundMapFragment) getSupportFragmentManager().findFragmentById(R.id.view_receipt_map))
.setListener(new WorkaroundMapFragment.OnTouchListener() {
#Override
public void onTouch() {
scrollViewRootLayout.requestDisallowInterceptTouchEvent(true);
}
});
onMapReady(mMap);
#Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
LatLng latLng = new LatLng(Double.valueOf(viewReceiptParser.receipt.Latitude), Double.valueOf(viewReceiptParser.receipt.Longitude));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng)
.zoom(14)
.build();
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
googleMap.addMarker(new MarkerOptions().position(latLng)/*.title(viewReceiptParser.receipt.VendorName)*/);
googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
#Override
public void onMapClick(LatLng latLng) {
launchGoogleMap();
}
});
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
launchGoogleMap();
return false;
}
});
}
Related
I'm using google map in my application ,when I click the marker info-window is opened again I want to click the info-window layout but its not working for layouts.If I give click listener for button means its working.Please help me to fix this issue.
Activity:
public class SampleFragment1 extends Fragment implements OnMapReadyCallback,GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener, LocationListener {
private ViewGroup infoWindow;
private TextView infoTitle;
private TextView infoSnippet,userNameTV,loggedLabel,userLastNameTV,time,distance,tasks;
private Button infoButton, infoButton2;
private OnInfoWindowElemTouchListener infoButtonListener;
LinearLayout markerlay;
GoogleMap mMap;
public void createLocationRequest() {
mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(UPDATE_INTERVAL);
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setSmallestDisplacement(DISPLACEMENT);
}
private MapView mapView;
private MarkerOptions mMarker;
MapWrapperLayout mapWrapperLayout;
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View view = inflater.inflate(R.layout.con_fragment_google, container, false);
mapWrapperLayout = (MapWrapperLayout)view.findViewById(R.id.map_relative_layout);
mapView = (MapView)view. findViewById(R.id.mapView);
// getContext().startService(new Intent(getContext(),GPSTracker.class));
mapView.onCreate(savedInstanceState);
buildGoogleApiClient();
createLocationRequest();
mapView.getMapAsync(this);
return view;
}
private synchronized void buildGoogleApiClient() {
try {
mGoogleApiClient = new GoogleApiClient.Builder(getContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void onConnected(#Nullable Bundle bundle) {
}
#Override
public void onConnectionSuspended(int i) {
}
// to get current latitude and longitude
// storing the updated latitde and longitude when user moving and reach destination
#Override
public void onLocationChanged(Location location) {
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mapWrapperLayout.init(mMap, getPixelsFromDp(getContext(), 39 + 20));
// We want to reuse the info window for all the markers,
// so let's create only one class member instance
this.infoWindow = (ViewGroup)getActivity().getLayoutInflater().inflate(R.layout.info_widow_layout, null);
this.infoTitle = (TextView)infoWindow.findViewById(R.id.nametv);
this.infoSnippet = (TextView)infoWindow.findViewById(R.id.addressTv);
this.infoButton = (Button)infoWindow.findViewById(R.id.clinicType);
// Setting custom OnTouchListener which deals with the pressed state
// so it shows up
this.infoButtonListener = new OnInfoWindowElemTouchListener(infoTitle
) //btn_default_pressed_holo_light
{
#Override
protected void onClickConfirmed(View v, Marker marker) {
// Here we can perform some action triggered after clicking the button
Toast.makeText(getContext(), marker.getTitle() + "'s button clicked!", Toast.LENGTH_SHORT).show();
}
};
this.infoTitle.setOnTouchListener(infoButtonListener);
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
#Override
public View getInfoWindow(Marker marker) {
return null;
}
#Override
public View getInfoContents(Marker marker) {
// Setting up the infoWindow with current's marker info
infoTitle.setText(marker.getTitle());
infoSnippet.setText(marker.getSnippet());
infoButtonListener.setMarker(marker);
// We must call this to set the current marker and infoWindow references
// to the MapWrapperLayout
mapWrapperLayout.setMarkerWithInfoWindow(marker, infoWindow);
return infoWindow;
}
});
// Let's add a couple of markers
}
public static int getPixelsFromDp(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
}
Note:Here I give click listener for textview ,the textview present inside the layout.
I implement google map view inside fragment, everything is working but Marker is not moving into new location its fixed. I tried long press,listeners,tapping on other part of map, Nothing works.
MapView Fragment
public class MapLocation_Fragment extends Fragment implements GoogleMap.OnMarkerDragListener,GoogleMap.OnMarkerClickListener,OnMapReadyCallback {
MapView mapView;
GoogleMap google_Map;
Marker Map_marker;
LatLng locclPosition;
double lati,longi;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.maplocation_fragment, container, false);
mapView = (MapView) view.findViewById(R.id.send_Location_MapView);
mapView.onCreate(savedInstanceState);
mapView.onResume();// Needed tog et the map to display immediately
lati=getArguments().getDouble("lat");
longi=getArguments().getDouble("longi");
locclPosition=new LatLng(lati,longi);
MapsInitializer.initialize(getActivity());
mapView.getMapAsync(this);
return view;
}
#Override
public void onResume() {
super.onResume();
mapView.onResume();
}
#Override
public void onPause() {
super.onPause();
mapView.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
#Override
public void onMarkerDragStart(Marker marker) {
Map_marker=marker;
}
#Override
public void onMarkerDrag(Marker marker) {
}
#Override
public void onMarkerDragEnd(Marker marker) {
}
#Override
public boolean onMarkerClick(Marker marker) {
return false;
}
#Override
public void onMapReady(GoogleMap googleMap) {
google_Map = googleMap;
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
google_Map.setOnMarkerClickListener(MapLocation_Fragment.this);
google_Map.setOnMarkerDragListener(MapLocation_Fragment.this);
google_Map.setTrafficEnabled(true);
google_Map.setBuildingsEnabled(true);
google_Map.setMapType(googleMap.MAP_TYPE_NORMAL); //THIS OPTION WILL SHOW MAP IN SATELLITE FORM
google_Map.addMarker(new MarkerOptions()
.position(locclPosition)
.title("Current Location")
.draggable(true));
CameraPosition cameraPosition=new CameraPosition.Builder().target(locclPosition).zoom(19).build();
google_Map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
I need to marker to move where ever user tap on map but after lot of effort its still not moving at all. Please help guys.
To make your marker move when dragging it you need to write some code in your onMarkerDragEnd method, basically to update the position of your marker (locclPosition) to where the dragging ends (new coordinates)
#Override
public void onMarkerDragEnd(Marker marker) {
locclPosition = marker.getPosition();
}
I have a problem with pressing an option in my navigationView (R.id.create_marker) I want to create a marker in my MapFragment, but I can not do it, any suggestions?
Code of MainActivity.java where I press the menu option:
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.create_marker:
Toast.makeText(MainActivity.this, "Crear Marker", Toast.LENGTH_SHORT).show();
// Create marker and display it on the map
break;
}
return false;
}
});
Code of MapFragment.java:
public class MapFragment extends Fragment
implements OnMapReadyCallback {
private View rootView;
private GoogleMap gMap;
private MapView mapView;
public MapFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_map, container, false);
return rootView;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mapView = (MapView) rootView.findViewById(R.id.map);
if (mapView != null) {
mapView.onCreate(null);
mapView.onResume();
mapView.getMapAsync(this);
}
}
#Override
public void onResume() {
super.onResume();
}
#Override
public void onMapReady(GoogleMap googleMap) {
}
}
This is the structure of my project:
To create a marker, you need to call addMarker method on your Map, once it's ready to be used.
public void onMapReady(GoogleMap googleMap) {
// Add a marker in Sydney, Australia,
// and move the map's camera to the same location.
LatLng sydney = new LatLng(-33.852, 151.211);
googleMap.addMarker(new MarkerOptions().position(sydney)
.title("Marker in Sydney"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
If you want your Map to open a marker for a fixed Lat-Lng, pass in the coordinates as shown in the code above, otherwise request location via Google Location Api and pass the obtained Lat-Lng values to the addMarker() method.
Title can be a bit complicated but the problem is literally as described. I'm trying to use google map fragment within a fragment stack. When the application starts the user will see a button and when the user pushes the button, current view will be replaced with map fragment. Currently, I'm able to replace the fragments but when the map fragment is shown, the view still has the button of previous fragment.Also I'm trying to replace fragments in one of the tabs of my app. Here is my code;
Map Fragment;
public class MapFragment extends Fragment {
MapView mMapView;
private GoogleMap googleMap;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_maps, 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;
try {
googleMap.setMyLocationEnabled(true);
} catch (SecurityException e) {
e.printStackTrace();
}
// For dropping a marker at a point on the Map
LatLng sydney = new LatLng(-34, 151);
googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker Title").snippet("Marker Description"));
// For zooming automatically to the location of the marker
CameraPosition cameraPosition = new CameraPosition.Builder().target(sydney).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
});
return rootView;
}
#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();
}
}
Home Fragment;
public class HomeFragment extends RootFragment {
public HomeFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Obtain the shared Tracker instance.
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.home_tab, container, false);
Button go = (Button)v.findViewById(R.id.btn_go);
go.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Intent intent = new Intent(getActivity(), MapFragment.class);
//startActivity(intent);
enterNextFragment();
}
});
return v;
}
#Override
public void onResume() {
super.onResume();
}
private void enterNextFragment() {
// Pushing MapView Fragment
Fragment fragment = Fragment.instantiate(this.getContext(), MapFragment.class.getName());
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment_mainLayout, fragment);
ft.commit();
}
}
Map Layout;
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Home Fragment;
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeFragment"
android:background="#android:color/white"
android:id="#+id/fragment_mainLayout">
<!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.AppCompatButton
android:id="#+id/btn_go"
android:layout_width="fill_parent"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_height="wrap_content"
android:layout_marginTop="170dp"
android:text="GO"/>
</FrameLayout>
Often you will want one Fragment to communicate with another, for
example to change the content based on a user event. All
Fragment-to-Fragment communication is done through the associated
Activity. Two Fragments should never communicate directly.
Your fragments shouldn't communicate directly according to the documentation.
If you've managed to communicate with your fragments considering the documentation. Then you can use this simple method to be able to change and reuse any fragment.
In your host activity :
private void changeFragment(Fragment frag, boolean saveInBackstack) {
String backStateName = ((Object) frag).getClass().getName();
try {
FragmentManager manager = getSupportFragmentManager();
if (manager.findFragmentByTag(backStateName) == null) {
//fragment not in back stack, create it.
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.container, frag, backStateName);
if (saveInBackstack) {
Log.d(TAG, "Change Fragment: addToBackTack " + backStateName);
transaction.addToBackStack(backStateName);
} else {
Log.d(TAG, "Change Fragment: NO addToBackTack");
}
transaction.commit();
} else {
manager.popBackStack();
}
} catch (IllegalStateException exception) {
Log.w(TAG, "Unable to commit fragment, could be activity as been killed in
}
}
just add android:background="#android:color/white" on the main view of the map_layout xml file
Here is the solution;
Home Fragment;
public class HomeFragment extends RootFragment {
private LocationManager locationManager;
public HomeFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Obtain the shared Tracker instance.
locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.home_tab, container, false);
Button go = (Button) v.findViewById(R.id.btn_go);
go.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), MapFragment.class);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//Toast.makeText(getContext(), "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show();
startActivity(intent);
}
}
});
return v;
}
#Override
public void onResume() {
super.onResume();
}
}
MapFragment (it is now fragmentActivity not fragment);
public class MapFragment extends FragmentActivity implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
LocationListener {
MapView mMapView;
private GoogleMap googleMap;
// private GoogleMap map;
private LocationRequest mLocationRequest;
private GoogleApiClient mGoogleApiClient;
private Location mLastLocation;
private Marker marker;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mMapView = (MapView) findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.onResume(); // needed to get the map to display immediately
try {
MapsInitializer.initialize(this.getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
mMapView.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap mMap) {
googleMap = mMap;
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location = null;
try {
googleMap.setMyLocationEnabled(true);
location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
} catch (SecurityException e) {
e.printStackTrace();
}
if (location != null) {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(40) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
}
}
I am trying to use two different Map Fragment in two different Fragment Activities. And as per the SupportMapFragment design, I am keeping the map key in the META TAG of the appilcation properties in Manifest file.
However my Map view is not clearing, it is showing same map with old points in the second Fragment eventhough I am calling "getMap().clear()". Please suggest
This is working fine untill and unless I dont use new MapFragment in a separate Activity, If I use new Mapfragment, it is taking the same map view, so the map view is not clearing.
Code :
MAP FRAGMENT
public class DisplayMapFragment extends SupportMapFragment implements
OnMarkerClickListener,OnInfoWindowClickListener {
View mMapViewContainer;
MapView mMapView;
private Utill utilClass = Utill.getInstance(false);
private View v;
private MapView mapView;
private GeoPoint p;
private MapController mc;
private String latstr = "";
private String lonstr = "";
private String name, address;
private double lat;
private double lng;
ArrayList<NearByItem> NearByList=new ArrayList<NearByItem>();
private LatLng mPosFija;
private ArrayList<Double> mlat, mlong;
private ViewGroup parent;
Utill utilclass=Utill.getInstance(false);
Bitmap bmp;
ImageView ivIcon;
StringBuilder sbc=new StringBuilder();
ProgressBar progressbar;
public ImageLoader imageLoader;
public DisplayMapFragment() {
super();
}
public static DisplayMapFragment newInstance(LatLng posicion) {
DisplayMapFragment frag = new DisplayMapFragment();
frag.mPosFija = posicion;
return frag;
}
#Override
public void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
NearByList=NearByMapActivity.fltrdNearByLists;
imageLoader=new ImageLoader(this.getActivity().getApplicationContext());
}
#Override
public View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2) {
View v = super.onCreateView(arg0, arg1, arg2);
mlat = new ArrayList<Double>();
mlong = new ArrayList<Double>();
parent=arg1;
if(NearByMapActivity.fltrdNearByLists!=null && !NearByMapActivity.fltrdNearByLists.isEmpty())
NearByList.addAll(NearByMapActivity.fltrdNearByLists);
else
NearByList.addAll(Utill.NearbyList);
NearByMapActivity parentActivity = (NearByMapActivity) getActivity();
return v;
}
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private List<OverlayItem> items;
private Drawable marker;
public MyItemizedOverlay(Drawable defaultMarker) {
super(defaultMarker);
items = new ArrayList<OverlayItem>();
marker = defaultMarker;
}
#Override
protected OverlayItem createItem(int index) {
return items.get(index);
}
#Override
public int size() {
return items.size();
}
#Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
boundCenterBottom(marker);
}
public void addItem(OverlayItem item) {
items.add(item);
}
public void populateNow() {
populate();
}
#Override
protected boolean onTap(int index) {
return true;
}
}
private void initMap() {
UiSettings settings = getMap().getUiSettings();
settings.setAllGesturesEnabled(true);
// settings.setMyLocationButtonEnabled(true);
settings.isZoomControlsEnabled();
getMap().setTrafficEnabled(true);
getMap().getMaxZoomLevel();
// getMap().setMyLocationEnabled(true);
if(NearByMapActivity.fltrdNearByLists!=null && !NearByMapActivity.fltrdNearByLists.isEmpty())
getMap().moveCamera(
CameraUpdateFactory.newLatLngZoom(
new LatLng(Double.parseDouble(NearByMapActivity.fltrdNearByLists.get(0).getLocationLat()),
Double.parseDouble(NearByMapActivity.fltrdNearByLists.get(0).getLocationLong())), 14));
getMap().isTrafficEnabled();
// getMap().addGroundOverlay(new GroundOverlayOptions().)
getMap().setOnMarkerClickListener(this);
getMap().setOnInfoWindowClickListener(this);
marker=new MarkerOptions()
.position(
new LatLng(
Double.parseDouble(item.getLocationLat()),
Double.parseDouble(item.getLocationLong())))
.title(""+item.getStoreTitle())
.icon(bitmapLoyalty
).snippet(sbc.toString());
else
marker=new MarkerOptions()
.position(
new LatLng(
Double.parseDouble(item.getLocationLat()),
Double.parseDouble(item.getLocationLong())))
.title(""+item.getStoreTitle())
.icon(bitmapIconNearBy
).snippet(sbc.toString());
Marker marker1=getMap().addMarker(marker);
PopupWindowAdapter view1=new PopupWindowAdapter();
this.getMap().setInfoWindowAdapter(view1);
// .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
bmp=BitmapFactory.decodeResource(getResources(),R.drawable.orgr_icon);
}
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
initMap();
getMap().addMarker(new MarkerOptions().position(new
LatLng(36.865814,-119.758399)).icon(BitmapDescriptorFactory.fromResource(R.drawable.red_pin)));
//getMap().addGroundOverlay(new GroundOverlay(null));
/* getMap().addGroundOverlay(new GroundOverlayOptions()
.image(image)
.positionFromBounds(bounds)
.transparency(0.5));
*/ }
#Override
public void onPause() {
super.onPause();
//getMap().clear();
}
public void onResume(){
super.onResume();
if(NearByMapActivity.mainMapView!=null)
//if(NearByMapActivity.mainMapView.getVisibility()==View.GONE)
NearByMapActivity.mainMapView.setVisibility(View.VISIBLE);
}
#Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
Log.e("cleared", "");
return false;
}
}
public void onStop(){
super.onStop();
//getMap().clear();
}
}
MAP ACTIVITY : Activity class to start Fragment.
public class NearByMapActivity extends FragmentActivity{
onCreate(){
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment frag=new DisplayMapFragment();
transaction.add(R.id.middle_view, frag);
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
transaction.addToBackStack(null);
transaction.commit();
}
}
You are probably affected by this bug:
https://code.google.com/p/gmaps-api-issues/issues/detail?id=5027&thanks=5027&ts=1362071369
Thank u so much!!!!!!!!!!!!!
I try this, and its work like a charm :)
public void hideStupidMaps() {
mMapView.getLayoutParams().height = 1;
mMapView.getLayoutParams().width = 1;
mMapView.invalidate();
mMapView.requestLayout();
}