How to Pre-fill locations

On websites like LinkedIn, there is a location input field that automatically fills in locations as you type them. I was looking to implement something similar on my website.

enter image description here

I was wondering how I would go about this, obviously there is too many locations to write them all myself. Is there an API that could do this? I was looking at Google’s places API, would that get the job done?