The geocoding result provides an array of address_components containing the types of address addresses for the request.
From my very limited testing, the more information is added in the request, the longer this address_components array becomes. When entering France, this is only the following:
> Object long_name: "France" short_name: "FR" types: Array[2] > 0: "country" > 1: "political"
When a city is added, there is a type called "locality". So you can go through this array, checking if there is a match between long_names and what the user entered, if only a city or country is typed, itβs easy, but there are many options like Rome / Rome Italy (spelling differences), and if the user entered the city and country, you must give priority to the city.
In the end, it sounds like a very fuzzy search and match, even if you created your own hash to match the user input of possible place images.
Here is my lazy approach:
Create var mapZoom = 13; (suppose this is a city)
Check if all user input is really the name of the country: if it matches long_name and the record type is "country", reduce mapZoom to 5.
Apply setCenter using this mapZoom variable.
source share