1. Replace my address with GPS coordinates
You can use Geocoding process to convert addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers on a map, or position the map. The Google Maps Geocoding API provides a direct way to access these services via an HTTP request. You can check here the example which uses the Geocoding service through the Google Maps JavaScript API to demonstrate the basic functionality.
A Google Maps Geocoding API request takes the following form:
https://maps.googleapis.com/maps/api/geocode/outputFormat?parameters
where outputFormat
may be either of the following values:
json
(recommended) indicates output in JavaScript Object Notation (JSON); or
xml
indicates output in XML
To access the Google Maps Geocoding API over HTTP, use:
http://maps.googleapis.com/maps/api/geocode/outputFormat?parameters
2. Put my marker at the center when I resize my page.
You can check on these related SO posts:
Move your map variable into a scope where the event listener can use
it. You are creating the map inside your initialize() function and
nothing else can use it when created that way.
var map; //<-- This is now available to both event listeners and the initialize() function
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(40.5472,12.282715),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
Hope this helps! :)