2

Is there any way by which we can show the particular country as default country in google map?

I have tried with the centre of some of the countries but it seems tedious. I have only country name say "India" and I need to do is, show "India" in focus when the app gets open.

Ronak Thakkar
  • 2,515
  • 6
  • 31
  • 45
Maddy
  • 4,525
  • 4
  • 33
  • 53
  • Can you please explain if you want to set marker or set overlay on country? – Samir Bhatt Oct 13 '17 at 05:24
  • Are you talking about this:- 1> https://stackoverflow.com/questions/14157536/how-do-i-set-default-location-and-zoom-level-for-google-map-api-v2 2> https://stackoverflow.com/questions/18932325/android-how-to-focus-on-current-position – InsaneCat Oct 13 '17 at 05:32
  • @SamirBhatt, I want to show the country center as a center of the map when user opens the app. – Maddy Oct 13 '17 at 05:33
  • @PranavBhatt, How will I get to know the center lat-lng of any country? – Maddy Oct 13 '17 at 05:34
  • 1
    @Maddy may be useful to you :- https://stackoverflow.com/questions/10008108/how-to-get-the-latitude-and-longitude-from-city-name-in-android – InsaneCat Oct 13 '17 at 05:40
  • @PranavBhatt, Let me try this – Maddy Oct 13 '17 at 05:41

2 Answers2

0

In your onMapReady() function set

LatLngBounds boundsIndia = new LatLngBounds(new LatLng(23.63936, 68.14712), new LatLng(28.20453, 97.34466));
int padding = 0; // offset from edges of the map in pixels
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(boundsIndia, padding);
 mMap.animateCamera(cameraUpdate);

When you open your map you will see only India country on map. You can do it for any other countries.

Yogesh Nikam Patil
  • 1,192
  • 13
  • 18
  • What if the country is dynamic? – Maddy Oct 14 '19 at 13:15
  • You can change the LatLng values dynamically.Or use HashMap and set country name as a key and Latlan as a value.use spinner to select country name and match country name with hashmap key and set values. – Yogesh Nikam Patil Oct 14 '19 at 13:32
  • Thanks, but if you check the question, I only had country name at the time of posting the question and there was no API available to get country latlng from the country name at that moment! I'm not sure if it is still available! – Maddy Oct 15 '19 at 04:10
-3

This shows Sydney and puts a marker on it https://developers.google.com/maps/documentation/android-api/map-with-marker

 public class MapsMarkerActivity extends AppCompatActivity
    implements OnMapReadyCallback {
    // Include the OnCreate() method here too, as described above.
    @Override
    public void onMapReady(GoogleMap googleMap) {
        // Add a marker in Sydney, Australia,
        // and move the map's camera to the same location.
        LatLng sydney = new LatLng(-33.852, 151.211);
        googleMap.addMarker(new MarkerOptions().position(sydney)
            .title("Marker in Sydney"));
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
Salih Akşit
  • 55
  • 10
  • It will show sydney and the latlng is static, I want it to be dynamic. What I want is camera focus of centre of country not the marker! – Maddy Jan 31 '17 at 13:16