Click on zoom button to show the whole country (Brazil) on Google Maps

Asked

Viewed 257 times

1

Hello I would like you to please help me with an example of how to do for when the user click a button next to the map cause the map to zoom in to show the whole country.

I couldn’t make a practical example. I think with this information you can understand what I want.

1 answer

1


HTML:

<input type="button" value="Brasil" id="moveToBrasil" /><br>
<div id="googleMap" style="width:500px;height:380px;"></div>

Javascript:

var map;

function initialize() {
  var mapProp = {
    center:new google.maps.LatLng(45,19),
    zoom:3,
    mapTypeId:google.maps.MapTypeId.ROADMAP
  };
  map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}

google.maps.event.addDomListener(window, 'load', initialize);

$('#moveToBrasil').click(function(){
    map.setCenter(new google.maps.LatLng( -14.235004 , -51.92528 ) );
});

Jsfiddle:

http://jsfiddle.net/giancarlodebian/6h3frLaz/4/

References:

https://developers.google.com/public-data/docs/canonical/countries_csv

Browser other questions tagged

You are not signed in. Login or sign up in order to post.