How can I show my location on google maps in android - android

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

Related

Set multiple marker in osmdroid

Hi everyone I'm using osmdroid in my application. I have a list of Latitude and Longitude sets and want to show them on the map and each one should be clickable means when I click on one of them it opens new specific activity. so how i suppose to do that ?
I want to do something just like this :
Sadly i couldn't find much information about working with osmdroid so any help would be appreciated.
This is how i used osmdroid map
mapView.setTileSource(TileSourceFactory.MAPNIK);
IMapController mapController = mapView.getController();
mapController.setZoom(9.5);
GeoPoint startPoint = new GeoPoint(34.796830, 48.514820);
mapController.setCenter(startPoint);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
And this is overlays with geopoints :
List<OverlayItem> mItem = new ArrayList<OverlayItem>();
Drawable mMarker = this.getResources().getDrawable(R.drawable.marker_default);
GeoPoint point;
if (nearestDiscountsList.size()>0) {
for (int i = 0; i < nearestDiscountsList.size(); i++) {
point = new
GeoPoint(Double.parseDouble(nearestDiscountsList.get(i).getLatitude()),
Double.parseDouble(nearestDiscountsList.get(i).getLongitude()));
OverlayItem overlayItem = new OverlayItem("Here",
"sampleDescription", point);
overlayItem.setMarker(mMarker);
mItem.add(overlayItem);
}
}
But I do not know where to add these ):
Even any sample code about this will do the job.

How can I add strings to my custom map marker in Android?

I have created a map marker that is positioned on my map by finding the users location, but I am trying to add strings to the map marker and cannot get it to work. Here is my onCreate method where the location is set. The last part of the method shows placing pinpoint at location, I thought that the overlay item would take string parameters as follows:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
// Displaying Zooming controls
mapView= (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
//Manually place a pin by touching the map
touchy t = new touchy();
overlayList = mapView.getOverlays();
overlayList.add(t);
compass = new MyLocationOverlay(Maps.this, mapView);
overlayList.add(compass);
controller = mapView.getController();
d = getResources().getDrawable(R.drawable.androidmarker);
//placing pinpoint at location
lm =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria crit = new Criteria();
towers = lm.getBestProvider(crit, false);
Location location = lm.getLastKnownLocation(towers);
if(location != null){
lat = (int) (location.getLatitude()* 1E6);
longi = (int) (location.getLongitude()* 1E6);
GeoPoint ourLocation = new GeoPoint(lat, longi);
controller.animateTo(ourLocation);
controller.setZoom(6);
OverlayItem overlayitem = new OverlayItem(ourLocation, "First string", "Second string");
HelloItemizedOverlay custom = new HelloItemizedOverlay(d, Maps.this);
custom.insertPinpoint(overlayitem);
overlayList.add(custom);
}
else{
Toast.makeText(Maps.this, "Couldn't get provider", Toast.LENGTH_SHORT).show();
}
}
Can anyone see what I am doing wrong? Is this the wrong way to do this? Eventually I want to pass a name and high-score to the location which will be retrieved from another class as two strings.
I appreciate any advice at all.
Follow the following tutorial:
http://codemagician.wordpress.com/2010/05/06/android-google-mapview-tutorial-done-right/
In this he is creating an ItemizedOverly
HelloItemizedOverlay extends ItemizedOverlay<OverlayItem>
This will help you in adding a map overlay with text

Too many custom markers on Maps

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?

how to show multi color map overlays or pins in android on google map?

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 to to make 2 MapView on one Activity?

Is it possible to make 2 MapView on one Activity ?
If so, How to make it ?
I've tried but no luck.
Thanks in advance.
The short answer is no.
Currently Android supports only one MapView per MapActivity.
yes possible, I used this code for two different kinds of maps------ 1. for getting gps location------2. for getting some location when it is searched by its area/city/country name. The code is,
public void mapDisplay(double lat, double lng, int arg){
if(arg == 1){
mapView = (MapView)findViewById(R.id.map_view);
}
else if (arg ==2 ){
mapView = (MapView)findViewById(R.id.map_view2);
}
mapView.setBuiltInZoomControls(true);
//mapView.setStreetView(true);
//mapView.setTraffic(true);
//mapView.setSatellite(true);
// to display the pin point
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
GeoPoint point = new GeoPoint((int) (lat * 1E6), (int)(lng * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "", "");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mapView.getController().setZoom(18);
mapView.getController().setCenter(point);
mapView.getController().animateTo(point);
mapView.invalidate();
}
Note: Make sure that you have set the ContentViews before calling this method and
int arg
is used here to indicate that which mapView is going to be called.....I used

Categories

Resources