Maps in TabActivity overlaps each other - android

I have implemented the TabActivity in which there are 3 tabs. And each tab contains a map view.
When I switch the tabs,
The map of one tab is shown on the top of map of other tap.
This is my code for maps inside tabs:
GoogleMap map;
public void mapshow(String Message,int mapId) {
// google map start
SupportMapFragment fragment;
fragment =(SupportMapFragment)getSupportFragmentManager().findFragmentById(mapId);
// Getting reference to Google Map
map = fragment.getMap();
// Clear all the markers from the Google Map
map.clear();
MarkerOptions markerOptions = new MarkerOptions();
LatLng point = new LatLng(latitude, longitude);
// Setting position for the marker
markerOptions.position(point);
// Setting custom icon for the marker
markerOptions.icon(BitmapDescriptorFactory
.fromResource(R.drawable.marker));
// Setting title for the info window
markerOptions.title(Message);
// markerOptions.snippet("Showing a demo map marker.");
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Move the camera to the user's location and zoom in!
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
latitude, longitude), 14.0f));
// Adding the marker to the map
Marker marker = map.addMarker(markerOptions);
marker.showInfoWindow();
map.setOnMarkerClickListener(this);
map.getUiSettings().setZoomControlsEnabled(false);
// end google
}
So how to hide the previously selected tab's map when I switch the tab?

Related

How to open the title of a marker in google maps v.3 when camera arrives above it?

I have a few markers added on a map. I'm using a model class to hold data, so I'm adding the markers using the following code:
LatLng latLng = new LatLng(model.getLat(), model.getLng());
MarkerOptions marker = new MarkerOptions().position(latLng).title(model.getName());
googleMap.addMarker(marker);
I'm also using a method to move the camera to a specific position on user click. My method looks like this:
private void moveCamera(Model model) {
moveCamera(new LatLng(model.getLat(), model.getLng()), DEFAULT_ZOOM);
}
So when the user clicks on the name of a location which is in a list, I'm moving the camera over that location. How can I automatically open the title of that marker, when the camera arrives above that location?
Thanks in advance!
You have this code to create your MarkerOptions:
LatLng latLng = new LatLng(model.getLat(), model.getLng());
MarkerOptions markerOption = new MarkerOptions().position(latLng).title(model.getName());
When you add the Marker to your map just keep a reference to the object:
Marker marker = googleMap.addMarker(markerOption);
Now you can show the info window:
marker.showInfoWindow();

Google maps marker how saved data

When I paint I need to bind some data marker when the marker, and I need to click on the marker to get data. How do I bind data and received data? i need help! thanks
You can bind your data to a Marker using a HashMap. The key will be the Marker itself and the value will be the data that you need to relate to your Marker (just a String in my example):
private Map<Marker, String> markers = new HashMap<>(); // Map to bind a Strings to Markers
// ...
Marker marker1 = map.addMarker(new MarkerOptions().position(new LatLng(52, 5)));
markers.put(marker1, "One");
Marker marker2 = map.addMarker(new MarkerOptions().position(new LatLng(52.1, 5.1)));
markers.put(marker2, "Two");
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(final Marker marker) {
Log.i("Marker", markers.get(marker)); // Query the map to get the String related to the clicked Marker
return false;
}
});

Show route and map icon by default - Mapfragment Android

Hi,
1. Please find the route and map icon in the highlighted area.
2. These are shown on touch of the my location blue circle .
3. want to show those icons by default, without the user touching, as soon as the map loads.
Below is the code :
protected void loadMap(GoogleMap googleMap, String latlng) {
if (googleMap != null) {
googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMapToolbarEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
String[] latlngAry = latlng.split(",");
double lat = Double.parseDouble(latlngAry[0]);
double lng = Double.parseDouble(latlngAry[1]);
LatLng latlong = new LatLng(lat, lng);
BitmapDescriptor defaultMarker =
BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE);
Marker marker = googleMap.addMarker(new MarkerOptions()
.position(latlong)
.title("My Location")
.icon(defaultMarker));
marker.showInfoWindow();
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlong, 18)); }
The overlay that appears when a marker is clicked, is created and destroyed on-the-spot implicitly. You can't manually show that (yet).
If you must have this functionality, you can create an overlay over your map with 2 ImageViews, and call appropriate intents when they're clicked:
// Directions
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?saddr=51.5, 0.125&daddr=51.5, 0.15"));
startActivity(intent);
// Default google map
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(
"http://maps.google.com/maps?q=loc:51.5, 0.125"));
startActivity(intent);
Note: you need to change the coordinates based on Marker's getPosition() and the user's location.
Now to hide the default overlay, all you need to do is return true in the OnMarkerClickListener. Although you loose the ability to show InfoWindows and center camera on the marker, you can imitate that simply enough:
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow();
mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
return true;
}
});

Add pin(not marker) to google map Android

How to add a pin(not a marker)to the google map in android?
I know how to add a marker, something like this:
map.addMarker(new MarkerOptions()
.position(new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()))
.title(getString(R.string.start_location_marker)));
But I want a pin, not a marker.
A pin looks like this:
pin
A marker looks like this:
marker
set your pin image to marker it is called custom marker
#Override
public void onMapReady(GoogleMap googleMap) {
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.pin);
LatLng latLng = new LatLng(21.4225, 39.8262);
googleMap.addMarker(new MarkerOptions().position(latLng).title("Mecca").icon(icon)).showInfoWindow();
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
}

android Google map API v2 doesn't display street names

I'm displaying a map using google maps API v2 but it doesn't show any street names. It shows the satellite image but no text. What am I doing wrong here?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gmaps);
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
map.setInfoWindowAdapter(new MyInfoWindowAdapter(this, getLayoutInflater()));
map.setOnMapLongClickListener(this);
map.setOnInfoWindowClickListener(this);
map.setOnMarkerClickListener(this);
mMyLocation = map.getMyLocation();
setMarkerOnLocation();
}
This works as designed. You are setting the map in Satellite mode and according to https://developers.google.com/maps/documentation/android/map#map_types
Satellite
Satellite photograph data. Road and feature labels are not visible.
Hybrid
Satellite photograph data with road maps added. Road and feature labels are also visible.
So you'll need to use the following if you want the labels to show:
GoogleMap map;
...
// Sets the map type to be "hybrid"
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
You have just given current location and didnt given any latitude and longitude points
For example:
LatLng one = new LatLng(13.549881,77.711792);//
Marker myMarkerOne = gm.addMarker(new MarkerOptions()
.position(one)
.title("Name of location")
.snippet("Name of street")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
and if you want to get dynamically means use json map parsing which is given here.

Categories

Resources