Google map in a web application is really a wonderful asset and it has a wide range of application in web development. A business house, for example, can have its own website and wants to put his contact details there. If one puts a Google map there, this is certainly a plus. Visual information is more impressive than textual information, so does the Google map. As a web developer, we come across varieties of web applications depending on the client requirements. For this article, I am trying to focus on when and where we need to extract latitudes and longitudes from a Google map and how.

I have a scenario, for example, I want a web application where I store information of banks and their branches throughout the country or globe. I want to store the address of each of the banks, their branches and furthermore when I show the information of a particular bank, I want it to appear its location on a Google map. The problem here is the Google map cannot be able to provide us the exact latitude and longitude of every single bank of our interest when we supply address information on Google map. The best solution for me in this problem is why not we use the Google map itself to extract our exact location and store in our database.

Here is a simple way to do this. We need to load the Google map in a place from where we store address information of a particular bank (in our example, but it may be anything of your interest/requirement) i.e. load Google map in a page from where you will be providing address information of a location. Now the Google map API provides us very useful functions and event handlers. We can use them to extract geo coordinates (latitudes and longitudes) of any place visible on the map. The best event handler we can use is ‘click’ event on a map. When you click on a Google map, a ‘click’ event is fired and we can write an event handler for this to get our desired information.

View Live Demo Download Source