How to to make 2 MapView on one Activity? - android

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

Related

android geopoint app with remote sqlite

This is my code (bellow),
how to remove geopoints form code, and read it from sqlite from server? i have more than 1000 geopoints so my code is too long.
I have created datebase allready, but dont know how to connect it from server.
public class SimpleMap extends MapActivity {
private MapView mapView;
List<Overlay> mapOverlays;
Drawable drawable;
Drawable drawable2;
MyLocationOverlay myLocationOverlay;
SimpleItemizedOverlay itemizedOverlay2;
SimpleItemizedOverlay itemizedOverlay;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
GeoPoint hr = new GeoPoint((int) (44.715513 * 1E6),
(int) (16.545410 * 1E6));
mapView.getController().animateTo(hr);
mapView.getController().setZoom(7);
mapOverlays = mapView.getOverlays();
myLocationOverlay = new FixedMyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
mapView.postInvalidate();
drawable = getResources().getDrawable(R.drawable.icon2);
itemizedOverlay2 = new SimpleItemizedOverlay(drawable, mapView);
itemizedOverlay2.setShowClose(true);
itemizedOverlay2.setShowDisclosure(false);
itemizedOverlay2.setSnapToCenter(false);
GeoPoint point1000 = new GeoPoint((int) (34.109798 * 1E6),
(int) (25.242270 * 1E6));
OverlayItem overlayItem1000 = new OverlayItem(point1000,
"point1000", "some text");
itemizedOverlay2.addOverlay(overlayItem1000);
mapOverlays.add(itemizedOverlay2);
Connecting to a remote database from a mobile device is a bad idea for a number of reasons, such as performance, security, and app extensibility. A quick search on SO will turn up many results that come to the same conclusion.
If you have control over the server, it would be best to set up a simple Web service that your app can use to retrieve geopoints. Then, rather than connecting to a database, your app would connect to a URL (e.g., using HttpUrlConnection) and download the location data. The server will need to send them in a format that is easy for your app to parse, such as a comma-separated list:
-82.8883,25.92834
2.5057,-60.90711
...
For each pair of points, create a GeoPoint, wrap it in an OverlayItem, and then add it to your Overlay.

Android: R.drawable.marker cannot be resolved or is not a field

Borrowing this code from several different tutorials on how to use Google maps on Android, I ran into a problem that "R.drawable.marker cannot be resolved or is not a field"
R.java is not being imported via the known bug in Eclipse.
public void onStart() {
super.onStart();
// Create an ItemizedOverlay to display a list of markers
Drawable defaultMarker = getResources().getDrawable(R.drawable.marker);
HelloItemizedOverlay placesItemizedOverlay = new HelloItemizedOverlay (defaultMarker, this);
GeoPoint point =new GeoPoint((int)(41.856451 * 1E6),
(int)(-87.604864 * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "Line 1", "Line 2");
List<Overlay> mapOverlays = mapView.getOverlays();
placesItemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(placesItemizedOverlay);
// mapView.getOverlays().add(placesItemizedOverlay);
}
You need to have a marker.png (or marker.jpeg or whatever) file in one or more of the drawable* directories in your project.

Remove pin mapview?

I am working on GoogleMap with MapView.Part of my project i am touching on the map and i am adding pin.My question is i want to remove pin which can added before. How can i do that i want to give Geopoint to the function.
Can anybody give me suggestion?
This is my code:`
public void AddPoint(Drawable drawable, MapView mapView, MotionEvent motionEvent) {
p = mapView.getProjection().fromPixels(
(int) motionEvent.getX(),
(int) motionEvent.getY()-50);
final MapController mc = mapView.getController();
mc.setZoom(16);
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
itemizedOverlay.addOverlay(new CustomOverlayItem(p,"","",""));
mapView.getOverlays().add(itemizedOverlay);
mc.animateTo(p);
mapView.invalidate();
}`
mapView.getOverlays().clear();
Call marker.remove(). To get the reference to the marker, you need to save the markers to a List when you create them, and then you can iterate over the List to find the ones you want.

How can I show my location on google maps in 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);

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

Categories

Resources