So you’ve seen posts in forums that show you how to fit all markers in Android’s map. However, you notice the top part gets cut off.

The solution is to set the top padding of the Google Map to the height of your marker Drawable.

Here is the code to have all markers shown in the map.

Now, to make sure all the markers get shown within the map, simply get the height of the Drawable and apply it to the map’s padding.

User Cristian in the StackOverflow forum provided some code on how to get the country name based on the Location’s latitude and longitude coordinates.

While this may work at first, you might find out while testing that on the 2nd try, the GeoLocation objects produces a NullPointerException.

This is actually because the Google Maps API has a limit on free requests. If you wish to make sure your app never crashes when it checks for the country name, you will have to pay.

When I searched in Google on how to get the current location in Android, I came across ┬áthe page in Android’s documentation about connecting to Google Play Services and initializing it.

I found out this was really not needed. If I could get the location without having to use this, all the better right?

User MrJre from the StackOverflow forum provided this very handy, useful, clean and non-Google Play Services type of code.

All you need are some broadcasters, receivers and listeners. This is how I did using some of his code. The code will try to get locations through GPS or WI-FI in case one or the other fails.

First off, place this code in a class.

Then create a broadcast class that will fire events to all listeners when a location has been found.

Next, create a listener for use in any Activity that may use location tracking.

All classes are now in place. The next thing to do is to implement the listener to your Activity.

In the onCreate() method, the fetchLocation() method is called and once a location is found, the broadcaster will fire the gotLocation() method to all listeners and return a Location object.

That’s it! And without having to use Google Play Services to get a location object.

Related Posts Plugin for WordPress, Blogger...