android google map markers dont shown - java

My application heve 3 tabs, one of tabs contain google map. When I start my application, I see map, I can zoom and move on map, but I don't see crated markers on it.
Maps activity have auto generated code:
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

Check if you have enabled maps for android in Google API Console. Check if you have followed all the steps mentioned in the Official Google Documentation. Your activity must extend FragmentActivity and to initialize GoogleMap object. Make sure you have added support library.
Try to create a map with this line:
MapFragment mMapFragment=MapFragment.newInstance(mapOptions());

Related

Add marker using Lat/Lng when Google Map loads

I want to know
if we can add marker in Google Maps using longitude and latitude provided from firebase database. When maps fragment is loaded.
In simple I want to add markers in Google Maps using my own longitude and latitude and it should mark all the places say if I have 10 place's lng and lat.
Now I want to show all 10 places on Google Maps and some additional information also
Yes you can. Ther is a function addMarker() on map object to do that:
#Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Hello world"));
}
Documentation:
https://developers.google.com/maps/documentation/android-api/marker

Google Maps Pin in my Android application

I need to display user inserted pins on the map that i will have in my application.
This pin needs to be visible to all the users using the app.
I have no clue how to implement this.
Can i get some help please?
Pins in Google Maps are called Markers and they are pretty simple to create.
Following what is documented from the Google Maps API here, you just use the addMarker() method to create a marker and can customize the options of where it should be placed and the title to show when it is clicked on
#Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Hello world"));
}

I'm not having setUpMapIfNeeded library in my MapsActivity.java file

I posted the code snippet below as I'm unable to find the command setUpMapIfNeeded();. When I type the necessary command, I get red lines everywhere. Can anyone help me out with this code? Also, I'm not getting any marker in my emulator.
I'm open to suggestions, please help me out. The min sdk version that I'm using is 17, and the android studio version is 2.1. I'm using the Googlemaps activity. I still don't understand why I'm not getting the setUpMapIfNeeded command and also the rest of the inbuilt code snippet.
Code screenshot
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
Also after trying the missing code I'm unable to get any marker.
Whereas, wherever I have search online I'm getting this tutorial.
If you are aware of any other code, do let me know.
When you use MapsActivty, there is no need for any extra code. All the neccessary code is generated by Android Studio itself. If you look at the tutorial, the code inside the setUpMapIfNeeded() is same as the code you have in your onCreate(). When you add the Google MapsActivty, all you need to show the map is the Google Maps API key. Paste the APi key in your "google_maps_api.xml"(inside values folder) and you are done. Run the application and you will get the map in your Activity.
Steps for acquiring the Google Maps API key is given in the google_maps_api.xml in comments.
Also if are adding your own markers, then use the following code
public void setMarkerOnMap(String name, LatLng l) {
// Creating a marker
MarkerOptions markerOptions = new MarkerOptions();
// Setting the position for the marker
markerOptions.position(l);
// Setting the title for the marker.
// This will be displayed on taping the marker
markerOptions.title(name);
// Placing a marker on the touched position
mMap.addMarker(markerOptions);
}
Call this function like this :
LatLng loc=new LatLng(latitude,longitude);
String str_placeName="Place Name";
setMarkerOnMap(str_placeName,loc);
You need to call setUpMapIfNeeded() in onCreate() method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
Check this tutorial and SO question on how to add markers.

How do I get the blue location dot to appear in my Android application?

I'm fairly new to Android programming and I'm a bit stuck. I have a map set up and now I want to add the blue flashing dot to the application to show where the user is on the map.
How do I do this?
Just try implementing this code, hope this works fine for you.
private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
If it does not work for you, try keep in touch with me.

Google maps marker show only icon

I want to display markers on google maps (android)
I used this code (like in the example in android developer):
The location, name and descripion are valid (I checked them via debug mode)
It shows me the icon on the desired location, however without the marker or the description and snippets. The following line
mMap.addMarker(MarkerOptions().position(location)
.title(poi.getName()).snippet(poi.getDescription())
.icon(BitmapDescriptorFactory.fromBitmap(image_item));
shows me only the icon without the title or snippest.
Thanks a lot
Did you follow the examples from the documentation? Also, the sample code bundled with the Google Play services SDK?
Edit: You can show an info window programmatically by calling showInfoWindow() on the target marker:
Marker marker = mMap.addMarker(new MarkerOptions()
.position(location)
.title(poi.getName())
.snippet(poi.getDescription())
.icon(BitmapDescriptorFactory.fromBitmap(image_item));
marker.showInfoWindow();
However, bear in mind that only one info window can be displayed at a time. If a user clicks on another marker, the current window will be hidden and the new info window will be displayed.
try this code.
This code is work on Google map with API V2
Add the inbuilt method of google.
public void onMapLongClick(LatLng point) {
// Getting the Latitude and Longitude of the touched location
latLng = point;
// Clears the previously touched position
myMap.clear();
// Animating to the touched position
myMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
// Creating a marker
markerOptions = new MarkerOptions();
// Setting the position for the marker
markerOptions.position(latLng);
// Adding Marker on the touched location with address
new ReverseGeocodingTask(getBaseContext()).execute(latLng);
tmpLatLng = latLng;
drawCircle(point);
btLocInfo.setEnabled(true);
}
This is not a rare problem the only way to fix it is to reinstall its the only way was able to fix it .
show icon without the title or snippest. use below code
LatLng newYork = new LatLng(40.7142, 74.0064);
Marker melbourne = map.addMarker(new MarkerOptions()
.position(newYork));
Edited:
show marker with title & Snippest & icon
map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
.title(string).snippet(string2).icon(BitmapDescriptorFactory.fromBitmap(image_item));

Categories