I have the following activity in my app that sets a geo location on a map fragment but when I click the activity in my testing it crashes with the following errors:
http://pastebin.com/6QhdL7z9
I looked through the errors but I can't make sense of why it is crashing as its referring to main as one of the reasons.
This is where I'm calling the code in the onCreate() for reference:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_gmit);
/*map = (MapView)findViewById(R.id.map);
map.setBuiltInZoomControls(true);*/
//code to add a map marker at GMIT geographic location
GoogleMap mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(53.271900177, -9.04889965057))
.title("GMIT Galway Location"));;
}
Android Studio or Eclipse?
Did you try searching on SO? ;)
com.google.android.maps.MapView ClassNotFoundException
Android - Google Maps API v2 - NoClassDefFoundError
Sounds like you did not export the library in your project.....
Related
i got this error when i extends ItemizedOverlay on Activity. How can i resolve this error ? can any one help me out here.
ItemizedOverlay is no longer available in Google Maps v2.
If you would like to display marker on a map you can user Marker class. You can create Marker object using MarkerOptions.
I'm attaching the simplest example:
#Override
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions()
.position(new LatLng(52.2330653, 20.9211106))
.title("Warsaw"));
}
In addition I recommend reading Google Maps Android API and Markers section.
You can make a marker draggable using:
MarkerOptions.draggable(boolean)
Marker.setDraggable(boolean)
You can also attach marker drag listener, you can find more here.
This question already has answers here:
Android Google maps API V2 center markers
(2 answers)
Closed 7 years ago.
I have recently deployed Google map API in my android application. The problem is that the marker placed on the map is not visible until user scroll/navigate over the view where map's fragment is deployed.
problem is" How to focus the Google map to the marker of a specific location on initializing.
EDITED: 25 AUGUST 2017
I have placed the marker for a particular location using following this blog post
PROBLEM
I am trying to view my marker directly when a user sees the map. Not by scrolling the map to see the marker.
You need to animate or move the map to the place where the marker is placed. I have pasted a snippet which should help you achieve that. Implement OnMapReadyCallback interfere and once the map is ready you should get a callback thru onMapReady(). This code only for your reference. You can place the marker related code wherever you need and works fine.
#Override
public void onMapReady(GoogleMap googleMap) {
LatLng location = new LatLng(<latitude>, <longitude>);
CameraPosition target = CameraPosition.builder().target(location).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(target), 5000, null);
googleMap.addMarker(new MarkerOptions().position(location));
}
I started a new project with the Google Maps template of Android Studio and just added a marker to the map.
LatLng location = new LatLng(lat, lng);
Marker marker = mMap.addMarker(new MarkerOptions()
.position(location)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
When I click the Marker there comes a little menu with a Google Maps icon on the bottom right corner:
How can I get rid of this thing? I couldn't find anything I even don't know how to call it but I really need to get rid of it.
You need to call setMapToolbarEnabled method of UiSettings
Like this:
#Override
public void onMapReady(GoogleMap googleMap) {
googleMap.getUiSettings().setMapToolbarEnabled(false);
// Do other staff
}
I'm making a Navigation based application for Android using API. I have successfully added Google Maps to my app. But now I want to add navigation marker (arrow like symbol) same as we see in official Navigation app of Google. I searched allot but didnt found anything. So can anyone help me out?
There is a link to a good read about this.
Try this:
GoogleMap map;
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world"));
I have added a map fragment to my application and added the following code to place a marker on the fragment.But I'm getting errors in the code snippet.I have included all relevant imports.
The errors are compile time and are as follows:
1.MapFragment cannot be resolved to a type.
2.GoogleMap cannot be resolved to a type.
3.LatLng cannot be resolved to a type.
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Hello world"));
Anyone have any ideas where the error is in the snippet? Thanks
I think you should check two things first
Is the Google Play Service project or library added to your project ? If not, check this link http://developer.android.com/google/play-services/setup.html
If you compile for android version < 11, you need to use supportFragmentManager instead of the normal FragmentManager :
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
In the last case, you also need to update the class used in your XML to class="com.google.android.gms.maps.SupportMapFragment"