Android Mapview Custom marker not working with Picasso - android

I am implementing android Mapview with Custom marker. The custom marker has a background view to which an image is asynchronously loaded. I am using Picasso to load image in to marker view. Here is the code I am using,
for(int i=0;i<10;i++)
{
// latitude and longitude
double latitude = getShop_latitude(i);
double longitude = getShop_longitude(i);
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude)).title("");
PicassoMarker pm = new PicassoMarker(marker,getActivity());
String url = PPConfig.IMAGE_URL + Uri.encode(getPpyOfferIcon(i));
Picasso.with(getActivity()).load(url).into(pm);
// Changing marker icon
builder.include(marker.getPosition());
// adding marker
googleMap.addMarker(marker);
}
Here is the class that extends Target
public class PicassoMarker implements Target {
private MarkerOptions mMarker;
private FragmentActivity mActivity;
public PicassoMarker(MarkerOptions marker,FragmentActivity activity) {
mMarker = marker;
mActivity = activity;
}
#Override
public int hashCode() {
return mMarker.hashCode();
}
#Override
public boolean equals(Object o) {
if(o instanceof PicassoMarker) {
MarkerOptions marker = ((PicassoMarker) o).mMarker;
return mMarker.equals(marker);
} else {
return false;
}
}
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
//Load Custom marker view
View markerView = mActivity.getLayoutInflater().inflate(R.layout.fragment_map_marker,
null);
ImageView image = (ImageView) markerView.findViewById(R.id.markerImage);
image.setImageBitmap(bitmap);
RelativeLayout rl = (RelativeLayout)markerView.findViewById(R.id.markerContent);
rl.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(view.getContext(), "Clicked", Toast.LENGTH_LONG).show();
}
});
mMarker.icon(BitmapDescriptorFactory
.fromBitmap(createDrawableFromView(mActivity, markerView)));
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
// Convert a view to bitmap
private Bitmap createDrawableFromView(Context context, View view) {
DisplayMetrics displayMetrics = new DisplayMetrics();
mActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));
view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
view.layout(0, 0, 107, 117);
view.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
}
But this code is not loading my custom marker view, instead its loading the default marker pin point. Whats going wrong here?
Thanks.

Your PicassoMarker will be garbage collected before your onBitmapLoaded() method is called asynchronously. So you need a reference to hold your PicassoMarker object.
sample code in Activity:
public class MainActivity extends FragmentActivity {
private PicassoMarker target;
private GoogleMap mMap;
private static LatLng goodLatLng = new LatLng(37, -120);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpMapIfNeeded();
MarkerOptions markerOne = new MarkerOptions().position(goodLatLng).title("");
target = new PicassoMarker(mMap.addMarker(markerOne));
Picasso.with(MainActivity.this).load("http://icons.iconarchive.com/icons/yellowicon/game-stars/256/Mario-icon.png").into(target);
}
}
Sample code in PicassoMaker:
public class PicassoMarker implements Target {
Marker mMarker;
PicassoMarker(Marker marker) {
Log.d("test: ", "init marker");
mMarker = marker;
}
#Override
public int hashCode() {
return mMarker.hashCode();
}
#Override
public boolean equals(Object o) {
if(o instanceof PicassoMarker) {
Marker marker = ((PicassoMarker) o).mMarker;
return mMarker.equals(marker);
} else {
return false;
}
}
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Log.d("test: ", "bitmap loaded");
mMarker.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
Log.d("test: ", "bitmap fail");
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
Log.d("test: ", "bitmap preload");
}
}

Try this code
Picasso.with(getActivity()).load(url).placeholder(R.mipmap.ic_launcher).resize(200, 200).into(img_profile, new Callback() {
#Override
public void onSuccess() {
DebugLog.e("Success");
dropPinEffect(mMap.addMarker(new MarkerOptions()
.position(markerLatLng)
.title("Title")
.snippet("Description")
.icon(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(getActivity(), marker)))));
}
#Override
public void onError() {
}
});

Related

How to access custom parameters in AsyncTask?

I want to load images asynchronously and show them on the infowindow. For this I made a custom class to store parameters. I need for this (marker, image) but my code throws a runtime exception saying it can't call getPosition on the marker I stored in the custom class instance.
What is the correct way to use AsyncTask with custom class instance parameters?
This is my code:
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
LatLng latLng = marker.getPosition();
// find location id in database
Location location = dbhandler.getLocationByLatLng(latLng);
final int id = location.getId();
addButton.setVisibility(View.VISIBLE);
addButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// open load image fragment
android.support.v4.app.FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
LoadImageFragment fragment = new LoadImageFragment();
// pass id to new fragment
Bundle bundle = new Bundle();
bundle.putInt("id", id);
fragment.setArguments(bundle);
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
});
removeButton.setVisibility(View.VISIBLE);
removeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// remove markers and images
}
});
class TaskParams {
Marker marker;
Location location;
Image image;
TaskParams() {
}
public Location getLocation() {
return this.location;
}
public Marker getMarker() {
return this.marker;
}
public Image getImage(){
return this.image;
}
public void setMarker(Marker marker) {
this.marker = marker;
}
public void setLocation(Location location) {
this.location = location;
}
public void setImage(Image image) {
this.image = image;
}
}
TaskParams taskParams = new TaskParams();
taskParams.setMarker(marker);
new AsyncTask<TaskParams, Void, TaskParams>() {
#Override
protected TaskParams doInBackground(TaskParams... params) {
TaskParams tParams = params[0];
Marker m = tParams.getMarker();
LatLng latLng = m.getPosition();
Location location = dbhandler.getLocationByLatLng(latLng);
tParams.setLocation(location);
return tParams;
}
// find image and text associated with Location
protected void onPostExecute(TaskParams taskParams) {
new AsyncTask<TaskParams, Void, TaskParams>() {
#Override
protected TaskParams doInBackground(TaskParams... params) {
TaskParams tParams = params[0];
Location location = tParams.getLocation();
try {
image = dbhandler.getImageByLocationId(location.getId());
tParams.setImage(image);
}
catch (Exception ex){
Log.d("debug", "failed to fetch image");
image = null;
}
return tParams;
}
#Override
protected void onPostExecute(TaskParams taskParams) {
Image image = taskParams.getImage();
// set image and description
if(image != null) {
infoImageView.setImageBitmap(image.getBitmap());
infoTextView.setText(image.getDescription());
Marker marker = taskParams.getMarker();
marker.showInfoWindow();
updateInfoWindow(image);
}
}
}.execute(taskParams);
}
}.execute(taskParams);
//marker.showInfoWindow();
return true;
}
});
// find Location in database
// Setting a custom info window adapter for the google map
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
#Override
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
#Override
public View getInfoContents(Marker arg0) {
// Getting view from the layout file info_window_layout
View v = getActivity().getLayoutInflater().inflate(R.layout.info_window_layout, null);
// Getting the position from the marker
final LatLng latLng = arg0.getPosition();
infoImageView = (ImageView) v.findViewById(R.id.infoImage);
infoTextView = (TextView) v.findViewById(R.id.infoText);
if(image != null) {
infoImageView.setImageBitmap(image.getBitmap());
infoTextView.setText(image.getDescription());
}
return v;
}
});
You can override the constructor. Something like:
private class MyAsyncTask extends AsyncTask<Void, Void, Void> {
public MyAsyncTask(boolean showLoading) {
super();
// do stuff
}
// doInBackground() et al.
}
Then, when calling the task, do something like:
new MyAsyncTask(true).execute(maybe_other_params);
This is more useful than creating member variables because it simplifies the task invocation. Compare the code above with:
MyAsyncTask task = new MyAsyncTask();
task.showLoading = false;
task.execute();

custom icon of cluster group in android

I want to change defult cluster group icon with my drawable icon.
Please check my code for cluster program.
MyClusterRenderer.java
public class MyClusterRenderer extends DefaultClusterRenderer<MyItem> {
public MyClusterRenderer(Context context, GoogleMap map,
ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
#Override
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
super.onBeforeClusterItemRendered(item, markerOptions);
markerOptions.title("").icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_both));// for marker
}
#Override
protected void onClusterItemRendered(final MyItem clusterItem, Marker marker) {
super.onClusterItemRendered(clusterItem, marker);
}
}
code in my fragment for setup cluser
googleMap.clear();
mClusterManager = new ClusterManager<MyItem>(getActivity(), googleMap);
googleMap.setOnMarkerClickListener(mClusterManager);
googleMap.setOnCameraChangeListener(mClusterManager);
readItems();
mClusterManager.setRenderer(new MyClusterRenderer(getActivity(), googleMap, mClusterManager));
The best way is
private val clusterIconGenerator = IconGenerator(context)
override fun getDescriptorForCluster(cluster: Cluster<PromotionMarker>): BitmapDescriptor {
clusterIconGenerator.setBackground(ContextCompat.getDrawable(context, R.drawable.background_marker))
val icon: Bitmap = clusterIconGenerator.makeIcon(cluster.size.toString())
return BitmapDescriptorFactory.fromBitmap(icon)
}
Try to change Cluster icon in onBeforeClusterRendered method instead of onBeforeClusterItemRendered :
#Override
protected void onBeforeClusterRendered(Cluster<MyItem> cluster, MarkerOptions markerOptions) {
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_both));
}
public class MyClusterRenderer extends DefaultClusterRenderer<MyItem> {
private final IconGenerator mClusterIconGenerator = new IconGenerator(
getActivity());
public MyClusterRenderer(Context context, GoogleMap map,
ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
View multiProfile = getActivity().getLayoutInflater().inflate(
R.layout.cluster_custome_icon, null);
mClusterIconGenerator.setContentView(multiProfile);
}
#Override
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
markerOptions.title("").icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_both));
super.onBeforeClusterItemRendered(item, markerOptions);
}
// #Override
// protected void onClusterItemRendered(final MyItem clusterItem, Marker marker) {
// super.onClusterItemRendered(clusterItem, marker);
//
// }
#Override
protected void onBeforeClusterRendered(Cluster<MyItem> cluster,
MarkerOptions markerOptions) {
Log.e("get_item_list_nir", "CallMap onBeforeClusterRendered 13");
try {
mClusterIconGenerator.setBackground(null);
Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster
.getSize()));
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
} catch (Exception e) {
e.printStackTrace();
Log.e("get_item_list_nir", "error 13.1 : " + e.toString());
}
Log.e("get_item_list_nir", "CallMap onBeforeClusterRendered 14");
}
}

adding a marker in image using picasso

Is it possible to add a marker on an image using any image library in android ?
so far I have loaded an image into ImageView using picasso and all the solutions I have googled involved adding marker in Google maps!
Just Like the marker center in the image
Picasso provides a generic Target interface you can use to implement your own image destination. Specifically, you will want to override onBitmapLoaded to populate your marker.
A basic implementation is given below.
public class PicassoMarker implements Target {
Marker mMarker;
PicassoMarker(Marker marker) {
mMarker = marker;
}
#Override
public int hashCode() {
return mMarker.hashCode();
}
#Override
public boolean equals(Object o) {
if(o instanceof PicassoMarker) {
Marker marker = ((PicassoMarker) o).mMarker;
return mMarker.equals(marker);
} else {
return false;
}
}
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
mMarker.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}}
You would use it like this:
marker = new PicassoMarker(myMarker);
Picasso.with(MainActivity.this).load(URL).into(marker);

Google Map V2 Lazy loading of marker image

Anybody please tell me how to do lazy loading of markers because all of my marker image are getting from server. I can be able to download it from server but this will be displayed only if there is a map movement ie The marker image get updated only if it's already cached, the object reference wouldn't work anymore , google map convert marker view to bitmap and set it. If the user keeps the map idle then it wouldn't load the image. :(
I spend almost a week and do the possible but it's -ve. If anyone can give a spark it would be really really helpful.
public class ROverViewRender extends DefaultClusterRenderer<RItem> {
private IconGenerator mIconGenerator;
private IconGenerator mClusterIconGenerator;
private RImageView mImageView;
private RImageView mImageVieStar;
private ImageView mClusterImageView;
private Context context;
private ClusterManager<RItem> mClusterManager;
private ImageLoader imageLoader;
public ROverViewRender(Context context, GoogleMap map, ClusterManager<RItem> clusterManager) {
super(context, map, clusterManager);
this.mClusterManager=clusterManager;
Activity activity = (Activity) context;
this.context=context;
mClusterIconGenerator=new IconGenerator(context);
View clustorIcon = activity.getLayoutInflater().inflate(R.layout.clustor_icon, null);
mClusterIconGenerator.setContentView(clustorIcon);
mIconGenerator=new IconGenerator(context);
View markerIcon = activity.getLayoutInflater().inflate(R.layout.marker_icon, null);
mIconGenerator.setContentView(markerIcon);
mImageView=(RImageView)markerIcon.findViewById(R.id.marker_image);
mImageVieStar=(RImageView)markerIcon.findViewById(R.id.marker_route_rating);
mClusterImageView=(NetworkImageView)clustorIcon.findViewById(R.id.cluster_image);
imageLoader=VolleySingleton.getInstance(context).getImageLoader();;
}
#Override
protected void onBeforeClusterItemRendered(final RItem item, MarkerOptions markerOptions) {
setMarkerImage(item,markerOptions);
Bitmap icon = mIconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}
#Override
protected void onBeforeClusterRendered(Cluster<RItem> cluster, MarkerOptions markerOptions) {
Drawable drawable =context.getResources().getDrawable(R.drawable.ic_launcher);
mClusterImageView.setImageDrawable(drawable);
Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}
#Override
protected boolean shouldRenderAsCluster(Cluster cluster) {
// Always render clusters.
return cluster.getSize() > 1;
}
#Override
protected void onClusterItemRendered(RItem clusterItem, Marker marker) {
RLog.e("Invoked the ....>>>>>");
// setMarkerImage(clusterItem);
}
private void setMarkerImage(RItem item,final MarkerOptions markerOptions){
RLog.e("Image setter invoked..."+item.getMarkerUrl());
mImageView.setImageUrl(item.getMarkerUrl(), imageLoader);
imageLoader.get(item.getMarkerUrl(), new ImageListener() {
public void onErrorResponse(VolleyError error) {
// imageView.setImageResource(R.drawable.icon_error); // set an error image if the download fails
}
public void onResponse(ImageContainer response, boolean arg1) {
RLog.e("Image download completed...");
if (response.getBitmap() != null) {
mImageView.setImageBitmap(response.getBitmap());
}
}
});
}
}
I wrote example code and it might be worked.
I use Picasso for image loading library.
complete code is below
https://github.com/sis-yoshiday/Example/tree/master/app/src/main/java/jp/sis/yoshiday/example/android/widget/map
class MyClusterRenderer extends DefaultClusterRenderer<MyClusterItem> {
private final IconGenerator iconGenerator;
private final IconGenerator clusterIconGenerator;
private final ImageView imageView;
private final ImageView clusterImageView;
private final int markerWidth;
private final int markerHeight;
public MyClusterRenderer(Context context, GoogleMap map,
ClusterManager<MyClusterItem> clusterManager) {
super(context, map, clusterManager);
// initialize cluster icon generator
clusterIconGenerator = new IconGenerator(context.getApplicationContext());
View clusterView = LayoutInflater.from(context).inflate(R.layout.marker_cluster, null);
clusterIconGenerator.setContentView(clusterView);
clusterImageView = (ImageView) clusterView.findViewById(R.id.image);
// initialize cluster item icon generator
iconGenerator = new IconGenerator(context.getApplicationContext());
imageView = new ImageView(context.getApplicationContext());
markerWidth = (int) getResources().getDimension(R.dimen.marker_width);
markerHeight = (int) getResources().getDimension(R.dimen.marker_height);
imageView.setLayoutParams(new ViewGroup.LayoutParams(markerWidth, markerHeight));
int padding = (int) getResources().getDimension(R.dimen.marker_space);
imageView.setPadding(padding, padding, padding, padding);
iconGenerator.setContentView(imageView);
}
#Override protected void onBeforeClusterItemRendered(MyClusterItem item,
MarkerOptions markerOptions) {
loadAsync(imageView, item.getImageUrl());
try {
Bitmap icon = iconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
BitmapUtils.recycle(icon);
} catch (Exception e) {
// FIXME workaround : called after Bitmap recycled
Log.e(TAG, e.getMessage(), e);
}
}
#Override protected void onBeforeClusterRendered(Cluster<MyClusterItem> cluster,
MarkerOptions markerOptions) {
Iterator<MyClusterItem> iterator = cluster.getItems().iterator();
loadAsync(clusterImageView, iterator.next().getImageUrl());
try {
Bitmap icon = clusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
BitmapUtils.recycle(icon);
} catch (Exception e) {
// FIXME workaround : called after Bitmap recycled
Log.e(TAG, e.getMessage(), e);
}
}
#Override
protected boolean shouldRenderAsCluster(Cluster cluster) {
return cluster.getSize() > 1;
}
private void loadAsync(final ImageView imageView, final String url) {
// first, get from cache
Bitmap bitmap = thumbCache.get(url);
if (bitmap == null || bitmap.isRecycled()) {
// if there are no cached entry or already recycled, start async load
Picasso.with(getActivity()).load(url).into(new Target() {
#Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
imageView.setImageBitmap(bitmap);
thumbCache.put(url, bitmap);
}
#Override public void onBitmapFailed(Drawable errorDrawable) {
imageView.setImageResource(R.drawable.ic_launcher);
}
#Override public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
} else {
imageView.setImageBitmap(bitmap);
}
}
}

Issue while using 2 map fragments in One application

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();
}

Categories

Resources