David
David

Reputation: 16736

How to set a Google Map's center by ID?

I have a good map on my page. I would like to set the center of it from a function call in javascript? Does the map have an elementID or anything I can reference it in javascript with?

Upvotes: 0

Views: 228

Answers (1)

user160820
user160820

Reputation: 15220

normally you first create an options obecjt wihich also contains center of the map like and then you pass it to map object.

var latlng = new google.maps.LatLng(geolen, geowidth);

var options = {

  center: latlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  disableDefaultUI: true,
  mapTypeControl: true,
  scaleControl: true
};

map = new google.maps.Map(document.getElementById("map_container"), options);

After creating a map, you can always manipulate the map options using map instance. I think you don't need any ElementID for setting or getting the center of map

Upvotes: 1

Related Questions