Displaying Custom Text In A Map Snippet, Android
Ok, I've been at this all day now, I give up trying to get this myself! I've declared the map and location private GoogleMap googleMap; declared the location static final LatLng S
Solution 1:
This below code may be helpful to you.
public class Stacky extends FragmentActivity implements OnMarkerClickListener {
static final LatLng SECC = new LatLng(55.8607,-4.2871); private GoogleMap mMap;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.basic_demo);
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2)).getMap();
mMap.setMyLocationEnabled(true);
setUpMap();
findSMSLocation();
// Setting a custom info window adapter for the google map
mMap.setInfoWindowAdapter(newInfoWindowAdapter() {
// Use default InfoWindow frame@OverridepublicViewgetInfoWindow(Marker marker) {
returnnull;
}
// Defines the contents of the InfoWindow@OverridepublicViewgetInfoContents(Marker marker) {
// Getting view from the layout file info_window_layoutView v = getLayoutInflater().inflate(R.layout.custom_info, null);
TextView tvLat = (TextView) v.findViewById(R.id.info);
tvLat.setText("info");
tvLat.setTextColor(Color.GREEN);
return v;
}
});
}
@OverrideprotectedvoidonPause() {
super.onPause();
}
@OverrideprotectedvoidonResume() {
super.onResume();
setUpMapIfNeeded();
}
publicvoidfindSMSLocation() {
// TODO Auto-generated method stubtry{
mMap.addMarker(newMarkerOptions().position(SECC).title("SECC").snippet("Exhibition Way, Glasgow, G3 8YW\nSports: Boxing, Gymnastics, Judo, Netball, Wrestling, Weightlifting"));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(SECC, 18.0f));
}catch(Exception e){
e.printStackTrace();
}
}
privatevoidsetUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2))
.getMap();
mMap.setMyLocationEnabled(true);
// Check if we were successful in obtaining the map.if (mMap != null) {
setUpMap();
}
}
}
privatevoidsetUpMap() {
mMap.getUiSettings().setCompassEnabled(true);
mMap.getUiSettings().setTiltGesturesEnabled(true);
mMap.getUiSettings().setRotateGesturesEnabled(true);
mMap.getUiSettings().setScrollGesturesEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setZoomGesturesEnabled(true);
}
@OverridepublicbooleanonMarkerClick(Marker marker) {
// TODO Auto-generated method stureturnfalse;
}
}
You do not need to add marker.showInfoWindow() into OnMarkerClickListner() interface.When you click n to marker then Custom window created and load with your custom textview.
Post a Comment for "Displaying Custom Text In A Map Snippet, Android"