Reputation: 125
Google map, it allows us to pin-point any location we want. After pin-pointing, there will be this "Bubble" pop up box at the top of the push-pin. May i know how to do the pop up window box? Any codes to show? I am using alert dialog box now, but i want it to be "Bubble" pop up window instead.
List<Overlay> mapOverlays = mapView.getOverlays();
MapOverlay mapOverlay = new MapOverlay();
mapOverlays.add(mapOverlay);
// obtain gps location
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
lm.requestLocationUpdates(
// LocationManager.GPS_PROVIDER,
LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
k = new GeoPoint((int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
mc.animateTo(k);
mc.setZoom(18);
// Add a location marker
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listofOverlays = mapView.getOverlays();
listofOverlays.clear();
listofOverlays.add(mapOverlay);
// invalidate() method forces the MapView to be redrawn
mapView.invalidate();
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
class MapOverlay extends com.google.android.maps.Overlay {
@Override
public boolean onTap(final GeoPoint p, MapView mapView) {
// TODO Auto-generated method stub
k = p;
mc = mapView.getController();
mc.animateTo(p);
mapView.invalidate();
Geocoder geoCoder = new Geocoder(getBaseContext(),
Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6, 1);
String add = "";
if (addresses.size() > 0) {
for (int i = 0; i < addresses.get(0)
.getMaxAddressLineIndex(); i++)
add += addresses.get(0).getAddressLine(i) + "\n";
txtAddress.setText("Address: " + add);
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
super.draw(canvas, mapView, shadow);
if (k != null) {
// ---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(k, screenPts);
// ---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.passenger);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
}
return true;
}
}
}
Upvotes: 1
Views: 2285
Reputation: 5749
Google doesn't provide an API to do this, take a look at this. Victor's answer gives a link to open source code which fits the bill.
Upvotes: 0
Reputation: 3446
I'm currently working on a mapping application where I also needed to display 'Bubble' popups and the following blog posts helped me quite a bit.
This first post shows how to use a 9-patch image embedded in a view to produce a popup. The code is ok but does leave a number of questions unanswered, some commenters have requested some additional source code for clarification.
This post from the Android Developers blog explains what a 9 patch image is an how to create one.
Using these two posts I was able to pull some code together which works well so hopefully you will be able to manipulate it to fit your needs too.
Upvotes: 1
Reputation: 47375
Sounds like you are looking for the InfoWindow. By the way, in newer versions of the API, they do not have rounded corners (they look more like boxes and less like bubbles). You can restore the old ones by requesting a previous version of the API in the javascript URL that loads the maps API.
Upvotes: 0