Lỗi top latitude should của google sate map năm 2024

Geocoding is the process of converting 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 or position the map.

Reverse geocoding is the process of converting geographic coordinates into a human-readable address (see ).

You can also use the geocoder to find the address for a given .

The Maps JavaScript API provides a Geocoder class for geocoding and reverse geocoding dynamically from user input. If instead you wish to geocode static, known addresses, see the Geocoding web service.

Getting started

Before using the Geocoding service in the Maps JavaScript API, first ensure that the Geocoding API is enabled in the Google Cloud Console, in the same project you set up for the Maps JavaScript API.

To view your list of enabled APIs:

  1. Go to the Google Cloud Console.
  2. Click the Select a project button, then select the same project you set up for the Maps JavaScript API and click Open.
  3. From the list of APIs on the Dashboard, look for Geocoding API.
  4. If you see the API in the list, you’re all set. If the API is not listed, enable it:
    1. At the top of the page, select ENABLE API to display the Library tab. Alternatively, from the left side menu, select Library.
    2. Search for Geocoding API, then select it from the results list.
    3. Select ENABLE. When the process finishes, Geocoding API appears in the list of APIs on the Dashboard.

Pricing and policies

Pricing

Effective July 16, 2018, a new pay-as-you-go pricing plan went into effect for Maps, Routes, and Places. To learn more about the new pricing and usage limits for your use of the JavaScript Geocoding service, see Usage and Billing for the Geocoding API.

Policies

Use of the Geocoding service must be in accordance with the policies described for the Geocoding API.

Geocoding Requests

Accessing the Geocoding service is asynchronous, since the Google Maps API needs to make a call to an external server. For that reason, you need to pass a callback method to execute upon completion of the request. This callback method processes the result(s). Note that the geocoder may return more than one result.

You access the Google Maps API geocoding service within your code via the

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

3 constructor object. The

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

4 method initiates a request to the geocoding service, passing it a

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

5 object literal containing the input terms and a callback method to execute upon receipt of the response.

The

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

5 object literal contains the following fields:

{ address: string, location: LatLng, placeId: string, bounds: LatLngBounds, componentRestrictions: GeocoderComponentRestrictions, region: string }

Required parameters: You must supply one, and only one, of the following fields:

  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 7 — The address which you want to geocode. or results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 8 — The results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 9 (or var geocoder; var map; function initialize() {
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(-34.397, 150.644);  
    var mapOptions = {  
      zoom: 8,  
      center: latlng  
    }  
    map = new google.maps.Map(document.getElementById('map'), mapOptions);  
    
    } function codeAddress() {
    var address = document.getElementById('address').value;  
    geocoder.geocode( { 'address': address}, function(results, status) {  
      if (status == 'OK') {  
        map.setCenter(results[0].geometry.location);  
        var marker = new google.maps.Marker({  
            map: map,  
            position: results[0].geometry.location  
        });  
      } else {  
        alert('Geocode was not successful for the following reason: ' + status);  
      }  
    });  
    
    } <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
    <input id="address" type="textbox" value="Sydney, NSW">  
    <input type="button" value="Encode" onclick="codeAddress()">  
    
    </div> </body>
  • for which you wish to obtain the closest, human-readable address. The geocoder performs a reverse geocode. See for more information. or var geocoder; var map; function initialize() {
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(-34.397, 150.644);  
    var mapOptions = {  
      zoom: 8,  
      center: latlng  
    }  
    map = new google.maps.Map(document.getElementById('map'), mapOptions);  
    
    } function codeAddress() {
    var address = document.getElementById('address').value;  
    geocoder.geocode( { 'address': address}, function(results, status) {  
      if (status == 'OK') {  
        map.setCenter(results[0].geometry.location);  
        var marker = new google.maps.Marker({  
            map: map,  
            position: results[0].geometry.location  
        });  
      } else {  
        alert('Geocode was not successful for the following reason: ' + status);  
      }  
    });  
    
    } <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
    <input id="address" type="textbox" value="Sydney, NSW">  
    <input type="button" value="Encode" onclick="codeAddress()">  
    
    </div> </body> 1 — The place ID of the place for which you wish to obtain the closest, human-readable address. See more about .

Optional parameters:

  • var geocoder; var map; function initialize() {
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(-34.397, 150.644);  
    var mapOptions = {  
      zoom: 8,  
      center: latlng  
    }  
    map = new google.maps.Map(document.getElementById('map'), mapOptions);  
    
    } function codeAddress() {
    var address = document.getElementById('address').value;  
    geocoder.geocode( { 'address': address}, function(results, status) {  
      if (status == 'OK') {  
        map.setCenter(results[0].geometry.location);  
        var marker = new google.maps.Marker({  
            map: map,  
            position: results[0].geometry.location  
        });  
      } else {  
        alert('Geocode was not successful for the following reason: ' + status);  
      }  
    });  
    
    } <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
    <input id="address" type="textbox" value="Sydney, NSW">  
    <input type="button" value="Encode" onclick="codeAddress()">  
    
    </div> </body> 2 — The var geocoder; var map; function initialize() {
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(-34.397, 150.644);  
    var mapOptions = {  
      zoom: 8,  
      center: latlng  
    }  
    map = new google.maps.Map(document.getElementById('map'), mapOptions);  
    
    } function codeAddress() {
    var address = document.getElementById('address').value;  
    geocoder.geocode( { 'address': address}, function(results, status) {  
      if (status == 'OK') {  
        map.setCenter(results[0].geometry.location);  
        var marker = new google.maps.Marker({  
            map: map,  
            position: results[0].geometry.location  
        });  
      } else {  
        alert('Geocode was not successful for the following reason: ' + status);  
      }  
    });  
    
    } <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
    <input id="address" type="textbox" value="Sydney, NSW">  
    <input type="button" value="Encode" onclick="codeAddress()">  
    
    </div> </body> 3 within which to bias geocode results more prominently. The var geocoder; var map; function initialize() {
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(-34.397, 150.644);  
    var mapOptions = {  
      zoom: 8,  
      center: latlng  
    }  
    map = new google.maps.Map(document.getElementById('map'), mapOptions);  
    
    } function codeAddress() {
    var address = document.getElementById('address').value;  
    geocoder.geocode( { 'address': address}, function(results, status) {  
      if (status == 'OK') {  
        map.setCenter(results[0].geometry.location);  
        var marker = new google.maps.Marker({  
            map: map,  
            position: results[0].geometry.location  
        });  
      } else {  
        alert('Geocode was not successful for the following reason: ' + status);  
      }  
    });  
    
    } <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
    <input id="address" type="textbox" value="Sydney, NSW">  
    <input type="button" value="Encode" onclick="codeAddress()">  
    
    </div> </body> 2 parameter will only influence, not fully restrict, results from the geocoder. See more information about below.
  • var geocoder; var map; function initialize() {
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(-34.397, 150.644);  
    var mapOptions = {  
      zoom: 8,  
      center: latlng  
    }  
    map = new google.maps.Map(document.getElementById('map'), mapOptions);  
    
    } function codeAddress() {
    var address = document.getElementById('address').value;  
    geocoder.geocode( { 'address': address}, function(results, status) {  
      if (status == 'OK') {  
        map.setCenter(results[0].geometry.location);  
        var marker = new google.maps.Marker({  
            map: map,  
            position: results[0].geometry.location  
        });  
      } else {  
        alert('Geocode was not successful for the following reason: ' + status);  
      }  
    });  
    
    } <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
    <input id="address" type="textbox" value="Sydney, NSW">  
    <input type="button" value="Encode" onclick="codeAddress()">  
    
    </div> </body> 5 — Used to restrict results to a specific area. See more information about below.
  • var geocoder; var map; function initialize() {
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(-34.397, 150.644);  
    var mapOptions = {  
      zoom: 8,  
      center: latlng  
    }  
    map = new google.maps.Map(document.getElementById('map'), mapOptions);  
    
    } function codeAddress() {
    var address = document.getElementById('address').value;  
    geocoder.geocode( { 'address': address}, function(results, status) {  
      if (status == 'OK') {  
        map.setCenter(results[0].geometry.location);  
        var marker = new google.maps.Marker({  
            map: map,  
            position: results[0].geometry.location  
        });  
      } else {  
        alert('Geocode was not successful for the following reason: ' + status);  
      }  
    });  
    
    } <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
    <input id="address" type="textbox" value="Sydney, NSW">  
    <input type="button" value="Encode" onclick="codeAddress()">  
    
    </div> </body> 6 — The region code, specified as a specified as a two-character (non-numeric) Unicode region subtag. In most cases, these tags map directly to familiar ccTLD ("top-level domain") two-character values. The var geocoder; var map; function initialize() {
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(-34.397, 150.644);  
    var mapOptions = {  
      zoom: 8,  
      center: latlng  
    }  
    map = new google.maps.Map(document.getElementById('map'), mapOptions);  
    
    } function codeAddress() {
    var address = document.getElementById('address').value;  
    geocoder.geocode( { 'address': address}, function(results, status) {  
      if (status == 'OK') {  
        map.setCenter(results[0].geometry.location);  
        var marker = new google.maps.Marker({  
            map: map,  
            position: results[0].geometry.location  
        });  
      } else {  
        alert('Geocode was not successful for the following reason: ' + status);  
      }  
    });  
    
    } <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
    <input id="address" type="textbox" value="Sydney, NSW">  
    <input type="button" value="Encode" onclick="codeAddress()">  
    
    </div> </body> 6 parameter will only influence, not fully restrict, results from the geocoder. See more information about below.

Geocoding Responses

The Geocoding service requires a callback method to execute upon retrieval of the geocoder's results. This callback should pass two parameters to hold the

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

8 and a

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

9 code, in that order.

Geocoding Results

The

{ "types":["locality","political"], "formatted_address":"Winnetka, IL, USA", "address_components":[{

"long_name":"Winnetka",
"short_name":"Winnetka",
"types":["locality","political"]
},{
"long_name":"Illinois",
"short_name":"IL",
"types":["administrative_area_level_1","political"]
},{
"long_name":"United States",
"short_name":"US",
"types":["country","political"]
}], "geometry":{
"location":[ -87.7417070, 42.1083080],
"location_type":"APPROXIMATE"
}, "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q" }

0 object represents a single geocoding result. A geocode request may return multiple result objects:

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

These fields are explained below:

  • { "types":["locality","political"], "formatted_address":"Winnetka, IL, USA", "address_components":[{
    "long_name":"Winnetka",  
    "short_name":"Winnetka",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Illinois",  
    "short_name":"IL",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"United States",  
    "short_name":"US",  
    "types":["country","political"]  
    
    }], "geometry":{
    "location":[ -87.7417070, 42.1083080],  
    "location_type":"APPROXIMATE"  
    
    }, "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q" } 1 is an array indicating the address type of the returned result. This array contains a set of zero or more tags identifying the type of feature returned in the result. For example, a geocode of "Chicago" returns "locality" which indicates that "Chicago" is a city, and also returns "political" which indicates it is a political entity. See more information about below.
  • { "types":["locality","political"], "formatted_address":"Winnetka, IL, USA", "address_components":[{
    "long_name":"Winnetka",  
    "short_name":"Winnetka",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Illinois",  
    "short_name":"IL",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"United States",  
    "short_name":"US",  
    "types":["country","political"]  
    
    }], "geometry":{
    "location":[ -87.7417070, 42.1083080],  
    "location_type":"APPROXIMATE"  
    
    }, "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q" } 2 is a string containing the human-readable address of this location. Often this address is equivalent to the postal address. Note that some countries, such as the United Kingdom, do not allow distribution of true postal addresses due to licensing restrictions. The formatted address is logically composed of one or more address components. For example, the address "111 8th Avenue, New York, NY" consists of the following components: "111" (the street number), "8th Avenue" (the route), "New York" (the city) and "NY" (the US state). Do not parse the formatted address programmatically. Instead you should use the individual address components, which the API response includes in addition to the formatted address field.
  • {

    "types":["locality","political"], "formatted_address":"Winnetka, IL, USA", "address_components":[{

    "long_name":"Winnetka",  
    "short_name":"Winnetka",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Illinois",  
    "short_name":"IL",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"United States",  
    "short_name":"US",  
    "types":["country","political"]  
    
    }], "geometry":{
    "location":[ -87.7417070, 42.1083080],  
    "location_type":"APPROXIMATE"  
    
    }, "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q" } 3 is an array containing the separate components applicable to this address. Each address component typically contains the following fields:

    • {
       "types":["locality","political"],  
       "formatted_address":"Winnetka, IL, USA",  
       "address_components":[{  
         "long_name":"Winnetka",  
         "short_name":"Winnetka",  
         "types":["locality","political"]  
       },{  
         "long_name":"Illinois",  
         "short_name":"IL",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "geometry":{  
         "location":[ -87.7417070, 42.1083080],  
         "location_type":"APPROXIMATE"  
       },  
       "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q"  
      
      } 1 is an array indicating the type of the address component. See the list of supported types.
    • {
       "types":["locality","political"],  
       "formatted_address":"Winnetka, IL, USA",  
       "address_components":[{  
         "long_name":"Winnetka",  
         "short_name":"Winnetka",  
         "types":["locality","political"]  
       },{  
         "long_name":"Illinois",  
         "short_name":"IL",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "geometry":{  
         "location":[ -87.7417070, 42.1083080],  
         "location_type":"APPROXIMATE"  
       },  
       "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q"  
      
      } 5 is the full text description or name of the address component as returned by the Geocoder.
    • {
       "types":["locality","political"],  
       "formatted_address":"Winnetka, IL, USA",  
       "address_components":[{  
         "long_name":"Winnetka",  
         "short_name":"Winnetka",  
         "types":["locality","political"]  
       },{  
         "long_name":"Illinois",  
         "short_name":"IL",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "geometry":{  
         "location":[ -87.7417070, 42.1083080],  
         "location_type":"APPROXIMATE"  
       },  
       "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q"  
      
      } 6 is an abbreviated textual name for the address component, if available. For example, an address component for the state of Alaska may have a {
       "types":["locality","political"],  
       "formatted_address":"Winnetka, IL, USA",  
       "address_components":[{  
         "long_name":"Winnetka",  
         "short_name":"Winnetka",  
         "types":["locality","political"]  
       },{  
         "long_name":"Illinois",  
         "short_name":"IL",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "geometry":{  
         "location":[ -87.7417070, 42.1083080],  
         "location_type":"APPROXIMATE"  
       },  
       "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q"  
      
      } 5 of "Alaska" and a {
       "types":["locality","political"],  
       "formatted_address":"Winnetka, IL, USA",  
       "address_components":[{  
         "long_name":"Winnetka",  
         "short_name":"Winnetka",  
         "types":["locality","political"]  
       },{  
         "long_name":"Illinois",  
         "short_name":"IL",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "geometry":{  
         "location":[ -87.7417070, 42.1083080],  
         "location_type":"APPROXIMATE"  
       },  
       "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q"  
      
      } 6 of "AK" using the 2-letter postal abbreviation. Note the following facts about the { "types":["locality","political"], "formatted_address":"Winnetka, IL, USA", "address_components":[{
      "long_name":"Winnetka",  
      "short_name":"Winnetka",  
      "types":["locality","political"]  
      
      },{
      "long_name":"Illinois",  
      "short_name":"IL",  
      "types":["administrative_area_level_1","political"]  
      
      },{
      "long_name":"United States",  
      "short_name":"US",  
      "types":["country","political"]  
      
      }], "geometry":{
      "location":[ -87.7417070, 42.1083080],  
      "location_type":"APPROXIMATE"  
      
      }, "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q" } 3 array:
    • The array of address components may contain more components than the {
       "types":["locality","political"],  
       "formatted_address":"Winnetka, IL, USA",  
       "address_components":[{  
         "long_name":"Winnetka",  
         "short_name":"Winnetka",  
         "types":["locality","political"]  
       },{  
         "long_name":"Illinois",  
         "short_name":"IL",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "geometry":{  
         "location":[ -87.7417070, 42.1083080],  
         "location_type":"APPROXIMATE"  
       },  
       "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q"  
      
      }
    • The array does not necessarily include all the political entities that contain an address, apart from those included in the {
       "types":["locality","political"],  
       "formatted_address":"Winnetka, IL, USA",  
       "address_components":[{  
         "long_name":"Winnetka",  
         "short_name":"Winnetka",  
         "types":["locality","political"]  
       },{  
         "long_name":"Illinois",  
         "short_name":"IL",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "geometry":{  
         "location":[ -87.7417070, 42.1083080],  
         "location_type":"APPROXIMATE"  
       },  
       "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q"  
      
      } 2. To retrieve all the political entities that contain a specific address, you should use reverse geocoding, passing the latitude/longitude of the address as a parameter to the request.
    • The format of the response is not guaranteed to remain the same between requests. In particular, the number of {
       "types":["sublocality","political"],  
       "formatted_address":"Winnetka, California, USA",  
       "address_components":[{  
         "long_name":"Winnetka",  
         "short_name":"Winnetka",  
         "types":["sublocality","political"]  
       },{  
         "long_name":"Los Angeles",  
         "short_name":"Los Angeles",  
         "types":["administrative_area_level_3","political"]  
       },{  
         "long_name":"Los Angeles",  
         "short_name":"Los Angeles",  
         "types":["administrative_area_level_2","political"]  
       },{  
         "long_name":"California",  
         "short_name":"CA",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "geometry":{  
         "location": [34.213171,-118.571022],  
         "location_type":"APPROXIMATE"  
       },  
       "place_id": "ChIJ0fd4S_KbwoAR2hRDrsr3HmQ"  
      
      } 2 varies based on the address requested and can change over time for the same address. A component can change position in the array. The type of the component can change. A particular component may be missing in a later response. See more information about below.
  • { "types":["sublocality","political"], "formatted_address":"Winnetka, California, USA", "address_components":[{
    "long_name":"Winnetka",  
    "short_name":"Winnetka",  
    "types":["sublocality","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_3","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"California",  
    "short_name":"CA",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"United States",  
    "short_name":"US",  
    "types":["country","political"]  
    
    }], "geometry":{
    "location": [34.213171,-118.571022],  
    "location_type":"APPROXIMATE"  
    
    }, "place_id": "ChIJ0fd4S_KbwoAR2hRDrsr3HmQ" } 3 indicates that the geocoder did not return an exact match for the original request, though it was able to match part of the requested address. You may wish to examine the original request for misspellings and/or an incomplete address. Partial matches most often occur for street addresses that do not exist within the locality you pass in the request. Partial matches may also be returned when a request matches two or more locations in the same locality. For example, "Hillpar St, Bristol, UK" will return a partial match for both Henry Street and Henrietta Street. Note that if a request includes a misspelled address component, the geocoding service may suggest an alternative address. Suggestions triggered in this way will also be marked as a partial match.
  • { "types":["sublocality","political"], "formatted_address":"Winnetka, California, USA", "address_components":[{
    "long_name":"Winnetka",  
    "short_name":"Winnetka",  
    "types":["sublocality","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_3","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"California",  
    "short_name":"CA",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"United States",  
    "short_name":"US",  
    "types":["country","political"]  
    
    }], "geometry":{
    "location": [34.213171,-118.571022],  
    "location_type":"APPROXIMATE"  
    
    }, "place_id": "ChIJ0fd4S_KbwoAR2hRDrsr3HmQ" } 4is a unique identifier of a place, which can be used with other Google APIs. For example, you can use the { "types":["sublocality","political"], "formatted_address":"Winnetka, California, USA", "address_components":[{
    "long_name":"Winnetka",  
    "short_name":"Winnetka",  
    "types":["sublocality","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_3","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"California",  
    "short_name":"CA",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"United States",  
    "short_name":"US",  
    "types":["country","political"]  
    
    }], "geometry":{
    "location": [34.213171,-118.571022],  
    "location_type":"APPROXIMATE"  
    
    }, "place_id": "ChIJ0fd4S_KbwoAR2hRDrsr3HmQ" } 4 with the Google Places API library to get details of a local business, such as phone number, opening hours, user reviews, and more. See the place ID overview.
  • { "types":["sublocality","political"], "formatted_address":"Winnetka, California, USA", "address_components":[{
    "long_name":"Winnetka",  
    "short_name":"Winnetka",  
    "types":["sublocality","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_3","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"California",  
    "short_name":"CA",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"United States",  
    "short_name":"US",  
    "types":["country","political"]  
    
    }], "geometry":{
    "location": [34.213171,-118.571022],  
    "location_type":"APPROXIMATE"  
    
    }, "place_id": "ChIJ0fd4S_KbwoAR2hRDrsr3HmQ" } 6 is an array denoting all the localities contained in a postal code, and is only present when the result is a postal code that contains multiple localities.
  • {

    "types":["sublocality","political"], "formatted_address":"Winnetka, California, USA", "address_components":[{

    "long_name":"Winnetka",  
    "short_name":"Winnetka",  
    "types":["sublocality","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_3","political"]  
    
    },{
    "long_name":"Los Angeles",  
    "short_name":"Los Angeles",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"California",  
    "short_name":"CA",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"United States",  
    "short_name":"US",  
    "types":["country","political"]  
    
    }], "geometry":{
    "location": [34.213171,-118.571022],  
    "location_type":"APPROXIMATE"  
    
    }, "place_id": "ChIJ0fd4S_KbwoAR2hRDrsr3HmQ" } 7 contains the following information:

    • results[]: {
      types[]: string,  
      formatted_address: string,  
      address_components[]: {  
        short_name: string,  
        long_name: string,  
        postcode_localities[]: string,  
        types[]: string  
      },  
      partial_match: boolean,  
      place_id: string,  
      postcode_localities[]: string,  
      geometry: {  
        location: LatLng,  
        location_type: GeocoderLocationType  
        viewport: LatLngBounds,  
        bounds: LatLngBounds  
      }  
      
      } 8 contains the geocoded latitude,longitude value. Note that we return this location as a results[]: {
      types[]: string,  
      formatted_address: string,  
      address_components[]: {  
        short_name: string,  
        long_name: string,  
        postcode_localities[]: string,  
        types[]: string  
      },  
      partial_match: boolean,  
      place_id: string,  
      postcode_localities[]: string,  
      geometry: {  
        location: LatLng,  
        location_type: GeocoderLocationType  
        viewport: LatLngBounds,  
        bounds: LatLngBounds  
      }  
      
      } 9 object, not as a formatted string.
    • {
       "types":["locality","political"],  
       "formatted_address":"Toledo, OH, USA",  
       "address_components":[{  
         "long_name":"Toledo",  
         "short_name":"Toledo",  
         "types":["locality","political"]  
       },{  
         "long_name":"Ohio",  
         "short_name":"OH",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "place_id": "ChIJeU4e_C2HO4gRRcM6RZ_IPHw"  
      
      }

      0 stores additional data about the specified location. The following values are currently supported:

      • {
               "types":["locality","political"],  
               "formatted_address":"Toledo, OH, USA",  
               "address_components":[{  
                 "long_name":"Toledo",  
                 "short_name":"Toledo",  
                 "types":["locality","political"]  
               },{  
                 "long_name":"Ohio",  
                 "short_name":"OH",  
                 "types":["administrative_area_level_1","political"]  
               },{  
                 "long_name":"United States",  
                 "short_name":"US",  
                 "types":["country","political"]  
               }],  
               "place_id": "ChIJeU4e_C2HO4gRRcM6RZ_IPHw"  
             }  
             1 indicates that the returned result reflects a precise geocode.  
      • { "types":["locality","political"], "formatted_address":"Toledo, OH, USA", "address_components":[{ "long_name":"Toledo", "short_name":"Toledo", "types":["locality","political"] },{ "long_name":"Ohio", "short_name":"OH", "types":["administrative_area_level_1","political"] },{ "long_name":"United States", "short_name":"US", "types":["country","political"] }], "place_id": "ChIJeU4e_C2HO4gRRcM6RZ_IPHw" } 2 indicates that the returned result reflects an approximation (usually on a road) interpolated between two precise points (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address.
      • { "types":["locality","political"], "formatted_address":"Toledo, OH, USA", "address_components":[{ "long_name":"Toledo", "short_name":"Toledo", "types":["locality","political"] },{ "long_name":"Ohio", "short_name":"OH", "types":["administrative_area_level_1","political"] },{ "long_name":"United States", "short_name":"US", "types":["country","political"] }], "place_id": "ChIJeU4e_C2HO4gRRcM6RZ_IPHw" } 3 indicates that the returned result is the geometric center of a result such as a polyline (for example, a street) or polygon (region).
      • { "types":["locality","political"], "formatted_address":"Toledo, OH, USA", "address_components":[{ "long_name":"Toledo", "short_name":"Toledo", "types":["locality","political"] },{ "long_name":"Ohio", "short_name":"OH", "types":["administrative_area_level_1","political"] },{ "long_name":"United States", "short_name":"US", "types":["country","political"] }], "place_id": "ChIJeU4e_C2HO4gRRcM6RZ_IPHw" } 4 indicates that the returned result is approximate.
    • { "types":["locality","political"], "formatted_address":"Toledo, OH, USA", "address_components":[{ "long_name":"Toledo", "short_name":"Toledo", "types":["locality","political"] },{ "long_name":"Ohio", "short_name":"OH", "types":["administrative_area_level_1","political"] },{ "long_name":"United States", "short_name":"US", "types":["country","political"] }], "place_id": "ChIJeU4e_C2HO4gRRcM6RZ_IPHw" } 5 stores the recommended viewport for the returned result.
    • var geocoder;
       var map;  
       function initialize() {  
         geocoder = new google.maps.Geocoder();  
         var latlng = new google.maps.LatLng(-34.397, 150.644);  
         var mapOptions = {  
           zoom: 8,  
           center: latlng  
         }  
         map = new google.maps.Map(document.getElementById('map'), mapOptions);  
       }  
       function codeAddress() {  
         var address = document.getElementById('address').value;  
         geocoder.geocode( { 'address': address}, function(results, status) {  
           if (status == 'OK') {  
             map.setCenter(results[0].geometry.location);  
             var marker = new google.maps.Marker({  
                 map: map,  
                 position: results[0].geometry.location  
             });  
           } else {  
             alert('Geocode was not successful for the following reason: ' + status);  
           }  
         });  
       }  
      
      <body onload="initialize()">
      <div id="map" style="width: 320px; height: 480px;"></div>  
       <div>  
         <input id="address" type="textbox" value="Sydney, NSW">  
         <input type="button" value="Encode" onclick="codeAddress()">  
       </div>  
      
      </body> 2 (optionally returned) stores the {
       "types":["locality","political"],  
       "formatted_address":"Toledo, OH, USA",  
       "address_components":[{  
         "long_name":"Toledo",  
         "short_name":"Toledo",  
         "types":["locality","political"]  
       },{  
         "long_name":"Ohio",  
         "short_name":"OH",  
         "types":["administrative_area_level_1","political"]  
       },{  
         "long_name":"United States",  
         "short_name":"US",  
         "types":["country","political"]  
       }],  
       "place_id": "ChIJeU4e_C2HO4gRRcM6RZ_IPHw"  
      
      } 7 which can fully contain the returned result. Note that these bounds may not match the recommended viewport. (For example, San Francisco includes the Farallon Islands, which are technically part of the city, but should not be returned in the viewport.)

The addresses will be returned by the Geocoder using the browser's preferred language setting, or the language specified when loading the API JavaScript using the

{ "types":["locality","political"], "formatted_address":"Toledo, OH, USA", "address_components":[{

"long_name":"Toledo",
"short_name":"Toledo",
"types":["locality","political"]
},{
"long_name":"Ohio",
"short_name":"OH",
"types":["administrative_area_level_1","political"]
},{
"long_name":"United States",
"short_name":"US",
"types":["country","political"]
}], "place_id": "ChIJeU4e_C2HO4gRRcM6RZ_IPHw" }

8 parameter. (For more information, see Localization.)

Address Types and Address Component Types

The

{ "types":["locality","political"], "formatted_address":"Winnetka, IL, USA", "address_components":[{

"long_name":"Winnetka",
"short_name":"Winnetka",
"types":["locality","political"]
},{
"long_name":"Illinois",
"short_name":"IL",
"types":["administrative_area_level_1","political"]
},{
"long_name":"United States",
"short_name":"US",
"types":["country","political"]
}], "geometry":{
"location":[ -87.7417070, 42.1083080],
"location_type":"APPROXIMATE"
}, "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q" }

1 array in the indicates the address type. The

{ "types":["locality","political"], "formatted_address":"Winnetka, IL, USA", "address_components":[{

"long_name":"Winnetka",
"short_name":"Winnetka",
"types":["locality","political"]
},{
"long_name":"Illinois",
"short_name":"IL",
"types":["administrative_area_level_1","political"]
},{
"long_name":"United States",
"short_name":"US",
"types":["country","political"]
}], "geometry":{
"location":[ -87.7417070, 42.1083080],
"location_type":"APPROXIMATE"
}, "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q" }

1 array may also be returned within a to indicate the type of the particular address component. Addresses returned by the geocoder may have multiple types; the types may be considered tags. For example, many cities are tagged with the

{ "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{

"long_name":"Toledo",
"short_name":"Toledo",
"types":["locality","political"]
},{
"long_name":"Toledo",
"short_name":"TO",
"types":["administrative_area_level_2","political"]
},{
"long_name":"Castilla-La Mancha",
"short_name":"CM",
"types":["administrative_area_level_1","political"]
},{
"long_name":"España",
"short_name":"ES",
"types":["country","political"]
}], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" }

1 and

{ "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{

"long_name":"Toledo",
"short_name":"Toledo",
"types":["locality","political"]
},{
"long_name":"Toledo",
"short_name":"TO",
"types":["administrative_area_level_2","political"]
},{
"long_name":"Castilla-La Mancha",
"short_name":"CM",
"types":["administrative_area_level_1","political"]
},{
"long_name":"España",
"short_name":"ES",
"types":["country","political"]
}], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" }

2 type.

The following types are supported and returned by the geocoder in both the address types and address component types:

  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 3 indicates a precise street address.
  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 4 indicates a named route (such as "US 101").
  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 5 indicates a major intersection, usually of two major roads.
  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 1 indicates a political entity. Usually, this type indicates a polygon of some civil administration.
  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 7 indicates the national political entity, and is typically the highest order type returned by the Geocoder.
  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 8 indicates a first-order civil entity below the country level. Within the United States, these administrative levels are states. Not all nations exhibit these administrative levels. In most cases, administrative_area_level_1 short names will closely match ISO 3166-2 subdivisions and other widely circulated lists; however this is not guaranteed as our geocoding results are based on a variety of signals and location data.
  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 9 indicates a second-order civil entity below the country level. Within the United States, these administrative levels are counties. Not all nations exhibit these administrative levels.
  • function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 0 indicates a third-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
  • function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 1 indicates a fourth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
  • function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 2 indicates a fifth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
  • function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 3 indicates a sixth-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
  • function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 4 indicates a seventh-order civil entity below the country level. This type indicates a minor civil division. Not all nations exhibit these administrative levels.
  • function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 5 indicates a commonly-used alternative name for the entity.
  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 2 indicates an incorporated city or town political entity.
  • function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 7 indicates a first-order civil entity below a locality. For some locations may receive one of the additional types: function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 8 to function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 9. Each sublocality level is a civil entity. Larger numbers indicate a smaller geographic area.
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 0 indicates a named neighborhood
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 1 indicates a named location, usually a building or collection of buildings with a common name
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 2 indicates a first-order entity below a named location, usually a singular building within a collection of buildings with a common name
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 3 indicates an encoded location reference, derived from latitude and longitude. Plus codes can be used as a replacement for street addresses in places where they do not exist (where buildings are not numbered or streets are not named). See https://plus.codes for details.
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 4 indicates a postal code as used to address postal mail within the country.
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 5 indicates a prominent natural feature.
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 6 indicates an airport.
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 7 indicates a named park.
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 8 indicates a named point of interest. Typically, these "POI"s are prominent local entities that don't easily fit in another category, such as "Empire State Building" or "Eiffel Tower".

An empty list of types indicates there are no known types for the particular address component, for example, Lieu-dit in France.

In addition to the above, address components may include the types below.

Note: This list is not exhaustive, and is subject to change.

  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 9 indicates the floor of a building address.
  • function initMap() { const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 8,  
    center: { lat: 40.731, lng: -73.997 },  
    
    }); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); document.getElementById("submit").addEventListener("click", () => {
    geocodeLatLng(geocoder, map, infowindow);  
    
    }); } function geocodeLatLng(geocoder, map, infowindow) { const input = document.getElementById("latlng").value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } window.initMap = initMap; 0 typically indicates a place that has not yet been categorized.
  • function initMap() { const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 8,  
    center: { lat: 40.731, lng: -73.997 },  
    
    }); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); document.getElementById("submit").addEventListener("click", () => {
    geocodeLatLng(geocoder, map, infowindow);  
    
    }); } function geocodeLatLng(geocoder, map, infowindow) { const input = document.getElementById("latlng").value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } window.initMap = initMap; 1 indicates a nearby place that is used as a reference, to aid navigation.
  • function initMap(): void { const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,  
    {  
      zoom: 8,  
      center: { lat: 40.731, lng: -73.997 },  
    }  
    
    ); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
    "click",  
    () => {  
      geocodeLatLng(geocoder, map, infowindow);  
    }  
    
    ); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } declare global { interface Window {
    initMap: () => void;  
    
    } } window.initMap = initMap; 8 indicates a named point of interest.
  • function initMap() { const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 8,  
    center: { lat: 40.731, lng: -73.997 },  
    
    }); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); document.getElementById("submit").addEventListener("click", () => {
    geocodeLatLng(geocoder, map, infowindow);  
    
    }); } function geocodeLatLng(geocoder, map, infowindow) { const input = document.getElementById("latlng").value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } window.initMap = initMap; 3 indicates a parking lot or parking structure.
  • function initMap() { const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 8,  
    center: { lat: 40.731, lng: -73.997 },  
    
    }); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); document.getElementById("submit").addEventListener("click", () => {
    geocodeLatLng(geocoder, map, infowindow);  
    
    }); } function geocodeLatLng(geocoder, map, infowindow) { const input = document.getElementById("latlng").value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } window.initMap = initMap; 4 indicates a specific postal box.
  • function initMap() { const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 8,  
    center: { lat: 40.731, lng: -73.997 },  
    
    }); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); document.getElementById("submit").addEventListener("click", () => {
    geocodeLatLng(geocoder, map, infowindow);  
    
    }); } function geocodeLatLng(geocoder, map, infowindow) { const input = document.getElementById("latlng").value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } window.initMap = initMap; 5 indicates a grouping of geographic areas, such as { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 2 and function codeAddress() { geocoder.geocode({ componentRestrictions: {
    country: 'AU',  
    postalCode: '2000'  
    
    } }, function(results, status) { if (status == 'OK') {
    map.setCenter(results[0].geometry.location);  
    var marker = new google.maps.Marker({  
      map: map,  
      position: results[0].geometry.location  
    });  
    
    } else {
    window.alert('Geocode was not successful for the following reason: ' + status);  
    
    } }); } 7, used for mailing addresses in some countries.
  • function initMap() { const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 8,  
    center: { lat: 40.731, lng: -73.997 },  
    
    }); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); document.getElementById("submit").addEventListener("click", () => {
    geocodeLatLng(geocoder, map, infowindow);  
    
    }); } function geocodeLatLng(geocoder, map, infowindow) { const input = document.getElementById("latlng").value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } window.initMap = initMap; 8 indicates the room of a building address.
  • function initMap() { const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 8,  
    center: { lat: 40.731, lng: -73.997 },  
    
    }); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); document.getElementById("submit").addEventListener("click", () => {
    geocodeLatLng(geocoder, map, infowindow);  
    
    }); } function geocodeLatLng(geocoder, map, infowindow) { const input = document.getElementById("latlng").value; const latlngStr = input.split(",", 2); const latlng = {
    lat: parseFloat(latlngStr[0]),  
    lng: parseFloat(latlngStr[1]),  
    
    }; geocoder
    .geocode({ location: latlng })  
    .then((response) => {  
      if (response.results[0]) {  
        map.setZoom(11);  
        const marker = new google.maps.Marker({  
          position: latlng,  
          map: map,  
        });  
        infowindow.setContent(response.results[0].formatted_address);  
        infowindow.open(map, marker);  
      } else {  
        window.alert("No results found");  
      }  
    })  
    .catch((e) => window.alert("Geocoder failed due to: " + e));  
    
    } window.initMap = initMap; 9 indicates the precise street number.
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 00, results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 01 and results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 02 indicate the location of a bus, train or public transit stop.

Status Codes

The

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

9 code may return one of the following values:

  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 04 indicates that no errors occurred; the address was successfully parsed and at least one geocode was returned.
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 05 indicates that the geocode was successful but returned no results. This may occur if the geocoder was passed a non-existent results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 7.
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 07 indicates that you are over your quota.
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 08 indicates that your request was denied. The web page is not allowed to use the geocoder.
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 09 generally indicates that the query ( results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 7, results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 11 or results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }
  • is missing.
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 13 indicates that the request could not be processed due to a server error. The request may succeed if you try again.
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 14 indicates that the request timed out or there was a problem contacting the Google servers. The request may succeed if you try again.

In this example, we geocode an address and place a marker at the returned latitude and longitude values. Note that the handler is passed as an anonymous function literal.

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

View example.

Viewport Biasing

You can instruct the Geocoding Service to prefer results within a given viewport (expressed as a bounding box). You do so by setting the

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

2 parameter within the

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

5 object literal to define the bounds of this viewport. Note that biasing only prefers results within the bounds; if more relevant results exist outside of these bounds, they may be included.

For example, a geocode for "Winnetka" generally returns this suburb of Chicago:

{ "types":["locality","political"], "formatted_address":"Winnetka, IL, USA", "address_components":[{

"long_name":"Winnetka",
"short_name":"Winnetka",
"types":["locality","political"]
},{
"long_name":"Illinois",
"short_name":"IL",
"types":["administrative_area_level_1","political"]
},{
"long_name":"United States",
"short_name":"US",
"types":["country","political"]
}], "geometry":{
"location":[ -87.7417070, 42.1083080],
"location_type":"APPROXIMATE"
}, "place_id": "ChIJW8Va5TnED4gRY91Ng47qy3Q" }

However, specifying a

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

2 parameter defining a bounding box for the San Fernando Valley of Los Angeles results in this geocode returning the neighborhood named "Winnetka" in that location:

{ "types":["sublocality","political"], "formatted_address":"Winnetka, California, USA", "address_components":[{

"long_name":"Winnetka",
"short_name":"Winnetka",
"types":["sublocality","political"]
},{
"long_name":"Los Angeles",
"short_name":"Los Angeles",
"types":["administrative_area_level_3","political"]
},{
"long_name":"Los Angeles",
"short_name":"Los Angeles",
"types":["administrative_area_level_2","political"]
},{
"long_name":"California",
"short_name":"CA",
"types":["administrative_area_level_1","political"]
},{
"long_name":"United States",
"short_name":"US",
"types":["country","political"]
}], "geometry":{
"location": [34.213171,-118.571022],
"location_type":"APPROXIMATE"
}, "place_id": "ChIJ0fd4S_KbwoAR2hRDrsr3HmQ" }

Region Code Biasing

You can set the Geocoding Service to return results biased to a particular region explicitly using the

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

6 parameter. This parameter takes a region code, specified as a two-character (non-numeric) Unicode region subtag. These tags map directly to familiar ccTLD ("top-level domain") two-character values such as "uk" in "co.uk" for example. In some cases, the

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

6 tag also supports ISO-3166-1 codes, which sometimes differ from ccTLD values ("GB" for "Great Britain" for example).

When using the

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

6 parameter:

  • Specify only one country or region. Multiple values are ignored, and could result in a failed request.
  • Use only two-character region subtags (Unicode CLDR format). All other inputs will result in errors.
  • Only the countries and regions listed in Google Maps Platform Coverage Details are supported.

Geocoding requests can be sent for every domain in which the main Google Maps application offers geocoding. Note that biasing only prefers results for a specific domain; if more relevant results exist outside of this domain, they may be included.

For example, a geocode for "Toledo" returns this result, as the default domain for the Geocoding Service is set to the United States:

{ "types":["locality","political"], "formatted_address":"Toledo, OH, USA", "address_components":[{

"long_name":"Toledo",
"short_name":"Toledo",
"types":["locality","political"]
},{
"long_name":"Ohio",
"short_name":"OH",
"types":["administrative_area_level_1","political"]
},{
"long_name":"United States",
"short_name":"US",
"types":["country","political"]
}], "place_id": "ChIJeU4e_C2HO4gRRcM6RZ_IPHw" }

A geocode for "Toledo" with the

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

6 field set to

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

22 (Spain) will return the Spanish city:

{ "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{

"long_name":"Toledo",
"short_name":"Toledo",
"types":["locality","political"]
},{
"long_name":"Toledo",
"short_name":"TO",
"types":["administrative_area_level_2","political"]
},{
"long_name":"Castilla-La Mancha",
"short_name":"CM",
"types":["administrative_area_level_1","political"]
},{
"long_name":"España",
"short_name":"ES",
"types":["country","political"]
}], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" }

Component Filtering

You can set the Geocoding Service to return address results restricted to a specific area, by using a components filter. Specify the filter in the parameter. Filter values support the same methods of spelling correction and partial matching as other geocoding requests.

The geocoder returns only the results that match all the component filters. That is, it evaluates the filter specifications as an AND, not an OR.

A components filter consists of one or more of the following items:

  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 4 matches long or short name of a route.
  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 2 matches against locality and sublocality types.
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 26 matches all the levels of administrative area.
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 27 matches postal codes and postal code prefixes.
  • { "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{
    "long_name":"Toledo",  
    "short_name":"Toledo",  
    "types":["locality","political"]  
    
    },{
    "long_name":"Toledo",  
    "short_name":"TO",  
    "types":["administrative_area_level_2","political"]  
    
    },{
    "long_name":"Castilla-La Mancha",  
    "short_name":"CM",  
    "types":["administrative_area_level_1","political"]  
    
    },{
    "long_name":"España",  
    "short_name":"ES",  
    "types":["country","political"]  
    
    }], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" } 7 matches a country name or a two letter ISO 3166-1 country code. Note: The API follows the ISO standard for defining countries, and the filtering works best when using the corresponding ISO code of the country.

The following example demonstrates using the parameter to filter by

{ "types":["locality","political"], "formatted_address":"Toledo, España", "address_components":[{

"long_name":"Toledo",
"short_name":"Toledo",
"types":["locality","political"]
},{
"long_name":"Toledo",
"short_name":"TO",
"types":["administrative_area_level_2","political"]
},{
"long_name":"Castilla-La Mancha",
"short_name":"CM",
"types":["administrative_area_level_1","political"]
},{
"long_name":"España",
"short_name":"ES",
"types":["country","political"]
}], "place_id": "ChIJ8f21C60Lag0R_q11auhbf8Y" }

7 and

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

27:

function codeAddress() { geocoder.geocode({ componentRestrictions: {

country: 'AU',
postalCode: '2000'
} }, function(results, status) { if (status == 'OK') {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
  map: map,
  position: results[0].geometry.location
});
} else {
window.alert('Geocode was not successful for the following reason: ' + status);
} }); }

Reverse Geocoding (Address Lookup)

The term geocoding generally refers to translating a human-readable address into a location on a map. The process of doing the converse, translating a location on the map into a human-readable address, is known as reverse geocoding.

Instead of supplying a textual

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

7, supply a comma-separated latitude/longitude pair in the

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

8 parameter.

The following example geocodes a latitude/longitude value and centers the map at that location, bringing up an info window with the formatted address:

TypeScript

function initMap(): void { const map = new google.maps.Map(

document.getElementById("map") as HTMLElement,
{
  zoom: 8,
  center: { lat: 40.731, lng: -73.997 },
}
); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); (document.getElementById("submit") as HTMLElement).addEventListener(
"click",
() => {
  geocodeLatLng(geocoder, map, infowindow);
}
); } function geocodeLatLng( geocoder: google.maps.Geocoder, map: google.maps.Map, infowindow: google.maps.InfoWindow ) { const input = (document.getElementById("latlng") as HTMLInputElement).value; const latlngStr = input.split(",", 2); const latlng = {
lat: parseFloat(latlngStr[0]),
lng: parseFloat(latlngStr[1]),
}; geocoder
.geocode({ location: latlng })
.then((response) => {
  if (response.results[0]) {
    map.setZoom(11);
    const marker = new google.maps.Marker({
      position: latlng,
      map: map,
    });
    infowindow.setContent(response.results[0].formatted_address);
    infowindow.open(map, marker);
  } else {
    window.alert("No results found");
  }
})
.catch((e) => window.alert("Geocoder failed due to: " + e));
} declare global { interface Window {
initMap: () => void;
} } window.initMap = initMap;

JavaScript

function initMap() { const map = new google.maps.Map(document.getElementById("map"), {

zoom: 8,
center: { lat: 40.731, lng: -73.997 },
}); const geocoder = new google.maps.Geocoder(); const infowindow = new google.maps.InfoWindow(); document.getElementById("submit").addEventListener("click", () => {
geocodeLatLng(geocoder, map, infowindow);
}); } function geocodeLatLng(geocoder, map, infowindow) { const input = document.getElementById("latlng").value; const latlngStr = input.split(",", 2); const latlng = {
lat: parseFloat(latlngStr[0]),
lng: parseFloat(latlngStr[1]),
}; geocoder
.geocode({ location: latlng })
.then((response) => {
  if (response.results[0]) {
    map.setZoom(11);
    const marker = new google.maps.Marker({
      position: latlng,
      map: map,
    });
    infowindow.setContent(response.results[0].formatted_address);
    infowindow.open(map, marker);
  } else {
    window.alert("No results found");
  }
})
.catch((e) => window.alert("Geocoder failed due to: " + e));
} window.initMap = initMap;

View example

Try Sample

Note that in the previous example we showed the first result by selecting

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

34. The reverse geocoder often returns more than one result. Geocoded addresses are not just postal addresses, but any way to geographically name a location. For example, when geocoding a point in the city of Chicago, the geocoded point may be labeled as a street address, as the city (Chicago), as its state (Illinois) or as a country (The United States). All are addresses to the geocoder. The reverse geocoder returns all of these results.

The reverse geocoder matches political entities (countries, provinces, cities and neighborhoods), street addresses, and postal codes.

Here's an example of the list of addresses that the above query may return:

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

0

Addresses are returned in the order of best to least matches. Generally, the more exact address is the most prominent result, as it is in this case. Note that we return different types of addresses, from the most specific street address to less specific political entities such as neighborhoods, cities, counties, states, etc. If you wish to match a more general address, you may wish to inspect the

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

35 field.

Note: Reverse geocoding is not an exact science. The geocoder will attempt to find the closest addressable location within a certain tolerance.

Retrieving an Address for a Place ID

Supply a

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

1 to find the address for a given place ID. The place ID is a unique identifier that can be used with other Google APIs. For example, you can supply the

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

1 returned by the Roads API to get the address for a snapped point. For more information about place IDs, see the place ID overview.

When you supply a

var geocoder; var map; function initialize() {

geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
  zoom: 8,
  center: latlng
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
} function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == 'OK') {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        position: results[0].geometry.location
    });
  } else {
    alert('Geocode was not successful for the following reason: ' + status);
  }
});
} <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div> </body>

1, the request cannot contain any of the following fields:

  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 7
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 40
  • results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } } 8
  • var geocoder; var map; function initialize() {
    geocoder = new google.maps.Geocoder();  
    var latlng = new google.maps.LatLng(-34.397, 150.644);  
    var mapOptions = {  
      zoom: 8,  
      center: latlng  
    }  
    map = new google.maps.Map(document.getElementById('map'), mapOptions);  
    
    } function codeAddress() {
    var address = document.getElementById('address').value;  
    geocoder.geocode( { 'address': address}, function(results, status) {  
      if (status == 'OK') {  
        map.setCenter(results[0].geometry.location);  
        var marker = new google.maps.Marker({  
            map: map,  
            position: results[0].geometry.location  
        });  
      } else {  
        alert('Geocode was not successful for the following reason: ' + status);  
      }  
    });  
    
    } <body onload="initialize()"> <div id="map" style="width: 320px; height: 480px;"></div> <div>
    <input id="address" type="textbox" value="Sydney, NSW">  
    <input type="button" value="Encode" onclick="codeAddress()">  
    
    </div> </body> 5

The following example accepts a place ID, finds the corresponding address, and centers the map at that location. It also brings up an info window showing the formatted address of the relevant place:

TypeScript

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

1

JavaScript

results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, place_id: string, postcode_localities[]: string, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }

2

View example

Try Sample

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-02-15 UTC.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }] Need to tell us more?