I have a Data Structure (ada) that stores lat/long, title and drawable for each marker. There are many markers (~500) and i would like to show the markers only on the currently viewable area. (The relevant code is posted below.)
for (int i = 0; i < ada.size(); i++) {
GeoPoint point = new GeoPoint(
(int) (Float.parseFloat(ada.get(i).latitude) * 1E6),
(int) (Float.parseFloat(ada.get(i).longitude) * 1E6));
Drawable d = new BitmapDrawable(ic.get(ada.get(i).brand_front_thumbnail));
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
OverlayItem overlayitem = new OverlayItem(
point, ada.get(i).title);
overlayitem.setMarker(d);
itemizedOverlay.addOverlay(overlayitem);
}
I can check if the geopoint is within screen coordinates and set drawable only if it is inside, but how do i update the map when the map is moved?
Related
I have a Data Structure (ada) that stores lat/long, title and drawable for each marker. There are many markers (~500) and i would like to show the markers only on the currently viewable area. (The relevant code is posted below.)
for (int i = 0; i < ada.size(); i++) {
GeoPoint point = new GeoPoint(
(int) (Float.parseFloat(ada.get(i).latitude) * 1E6),
(int) (Float.parseFloat(ada.get(i).longitude) * 1E6));
Drawable d = new BitmapDrawable(ic.get(ada.get(i).brand_front_thumbnail));
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
OverlayItem overlayitem = new OverlayItem(
point, ada.get(i).title);
overlayitem.setMarker(d);
itemizedOverlay.addOverlay(overlayitem);
}
I can check if the geopoint is within screen coordinates and set drawable only if it is inside, but how do i update the map when the map is moved?
I have a google maps app that takes an array of points and puts them on a map. I want to add the little blue dot that moves as the user moves around. I haven't found any tutorials on how to do this. Here is an example of what I need
Note that the blue dot also has a blue ring that pulsates and it follows you when you start walking.
Thanks
EDIT I have found the function drawMyLocation, however I do not know where to place it. Here is my map activity and my itemized overlay (I am using a balloon itemized overlay to create the popup dialog effect)
MapView mapView = (MapView) findViewById(R.id.mapView);
List<Overlay> mapOverlays = mapView.getOverlays();
for (int i = 0; i < mList.size(); i++) {
Drawable drawable = null;
for (int k = 0; k < ImTracking.pList.size(); k++) {
if (mList.get(i).getId()
.equals(ImTracking.pList.get(k).getid())) {
mList.get(i).setName(
ImTracking.pList.get(k).getName());
if (mList.get(i).getMostRecent()) {
drawable = Maps.this.getResources()
.getDrawable(
pincolorstar[ImTracking.pList
.get(k).getPosition()]);
} else {
drawable = Maps.this
.getResources()
.getDrawable(
ImTracking.pincolors[ImTracking.pList
.get(k).getPosition()]);
}
}
}
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(
drawable, mapView);
GeoPoint myPoint = new GeoPoint((int) (mList.get(i)
.getLatitude() * 1E6), (int) (mList.get(i)
.getLongitude() * 1E6));
OverlayItem overlayitem = new OverlayItem(myPoint, mList
.get(i).getName(), mList.get(i).getTime());
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
The above part adds all the pins to the map, the next part is where I attempt to add the mylocation overlay
MyLocationOverlay myLocationOverlay=new MyLocationOverlay(Maps.this, mapView);
myLocationOverlay.enableMyLocation();
mapOverlays.add(myLocationOverlay);
MapController mc = mapView.getController();
mc.zoomToSpan(Math.abs(maxLat - minLat),
Math.abs(maxLon - minLon));
mc.animateTo(new GeoPoint((maxLat + minLat) / 2,
(maxLon + minLon) / 2));
} catch (Exception e) {
e.printStackTrace();
}
Just adding myLocationOverlay to mapOverlays does not display the blue dot.
You might want to see MyLocationOverlay and see if that can fit into your requirement
Sample illustration below:
List overlaysoverlays = mapView.getOverlays();
// "this" refers to your activity
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
myLocationOverlay.enableMyLocation();
overlays.add(myLocationOverlay);
I need your quick assistance for the problem stated below
In my android application I show a marker on specific location.
Here is my code
double latitude = Double.parseDouble(this.latitude);
double longitude = Double.parseDouble(this.longitude);
int latitudeE6 = (int) (latitude * 1e6);
int longitudeE6 = (int) (longitude * 1e6);
Log.i("Latitude","String = "+this.latitude+",Double = "+latitude+", int = "+latitudeE6);
Log.i("Longitude","String = "+this.longitude+",Double = "+longitude+", int = "+longitudeE6);
GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
Log.i("Point a", ""+point.getLatitudeE6()+","+point.getLongitudeE6());
OverlayItem overlay = new OverlayItem(point, title, detail);
Drawable drawable = mapView.getContext().getResources().getDrawable(
R.drawable.pin);
HelloOverlayItem helloOverLay = new HelloOverlayItem(drawable, this);
Log.i("Point b", ""+point.getLatitudeE6()+","+point.getLongitudeE6());
helloOverLay.addOverlay(overlay);
mapView.getOverlays().add(helloOverLay);
MapController controller = mapView.getController();
Log.i("Point c", ""+point.getLatitudeE6()+","+point.getLongitudeE6());
controller.animateTo(point);
controller.setCenter(point);
controller.setZoom(10);
I can get proper location integers in "Point C" log entry, which is not 0,0 (some where near London) But in map it always show me on 0,0 how can it be possible?? How to get rid of this??
I can't say that it's surely an answer or just a work around until it create some bug. But calling mapView.invalidate() worked. I have added this line exactly after mapView.getOverlays().add(helloOverLay); And it worked.
friends,
right now i am showing list of map overlays on google map using following code
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.balloon);
itemizedOverlay = new MarkerItemizedOverlay(drawable,this);
GeoPoint point;
OverlayItem overlayitem;
for (DalMapSearch t : Sr)
{
if(t != null)
{
point = new GeoPoint((int) (t.getLati() * 1E6), (int) (t.getLongi() * 1E6));
overlayitem = new OverlayItem(point, heading, t.getAd_text()+", "+t.getLocation()+"##"+t.getAd_id());
itemizedOverlay.addOverlay(overlayitem);
}
}
mapOverlays.add(itemizedOverlay);
// marker code goes here
mc.animateTo(myLocation);
mc.setZoom(12);
mapView.invalidate();
so in such a scenario balloon is displayed i want to show other images too depened upon category or a if statement.
any one guide me how can i show different images as a map overlay? for example images are imageA,ImageB,ImageC
any help would be appreciated.
GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());
drawable = this.getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new MyItemizedOverlay(drawable);
OverlayItem overlayItem = new OverlayItem(point, "", "");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
GeoPoint point2 = new GeoPoint(lt2.intValue(),long2.intValue() );
// All "B"s
drawable = this.getResources().getDrawable(R.drawable.icon);
itemizedOverlay = new MyItemizedOverlay(drawable);
OverlayItem overlayItem1 = new OverlayItem(point2, "", "");
itemizedOverlay.addOverlay(overlayItem1);
mapOverlays.add(itemizedOverlay);
how can i add different overlays at different zoom levels ? For instance i have an overlay image of a festival area that ive added onto the map which is great. But when the user zooms out i want to change the image that the user see's .Does anyone know how to do this?
The only thing that I can think of is to pass the zoom level into the overlay when it changes in the map and then make the decision on what to draw in the overlay.
I was having same problem but what you can do is define the size of bitmap based on difference of two geopoints e.g.
GeoPoint PointC = new GeoPoint((int)(35.496392 * 1E6), (int)(-97.5375950 * 1E6));
GeoPoint PointR = new GeoPoint((int)(35.496392 * 1E6), (int)(-97.5362690 * 1E6));
GeoPoint PointH = new GeoPoint((int)(35.696392 * 1E6), (int)(-97.5362690 * 1E6));
Point poC = new Point();
Point poR = new Point();
Point poH = new Point();
projection.toPixels(ovalR, poR);
projection.toPixels(ovalC, poC);
projection.toPixels(ovalH, poH);
cWidth = Math.abs(poC.x-poR.x);
cHieght = Math.abs(poC.y-poH.y);
Bitmap bitmap= Bitmap.createScaledBitmap(mBitmap, cWidth, cHeight, true);
If you control the zoom buttons (by having your own buttons), you may simply change the displayed overlays by modifying the array mapView.getOverlays() and then call mapView.invalidate().
I didn't try to change it so frequently but it should probably work.