I want to generate latitude and longitude automatically for CiviCRM contact when the address is present.
How to achieve this?
You need to enable Mapping and Geocoding from
Enter your API Key or Application ID. An API Key is required for the Google Maps API. Refer to developers.google.com for the latest information.
Save the form and you should be able to see latitude and longitude based on your contact's address. Note that it displays when you click on inline edit and load the address form as shown below.
Welcome to Stackexchange. Take a look at the docs about geocoding and mapping. If you're using Google then you need an API key for geo coding requests. To get Google API key you can find information here.
Once you have api key navigate CiviCRM >> Administer >> System Settings >> Mapping and Geocoding and set the API key there.
After enabling the mapping provider, you may need to use this script to generate latitude/longitude information for existing contact addresses.
You can also use CiviCRM Geocoder extension which provides additional information about the address.