-1

I have included a google map in my website. I have the location of a person stored in a string. Is there a way to put a marker in google maps based on that location? If I had the location as coordinates it's easy, it's explained in google developers blog pretty straight forward.

Is there a way to extract coords from that location, or somehow search in google maps and place a marker on the returned location?

John Demetriou
  • 4,093
  • 6
  • 52
  • 88

1 Answers1

2

You could use Google's geocoding service to get coords from street addresses.

You can send a request to the API server, and it returns an XML structure containing a latlng coord, but you can also have JSON.

The service is free, within limits.

Here's an example of an API call.

https://maps.googleapis.com/maps/api/geocode/xml?address=PLACENAME

I've used this service before. You'd want to have the most specific details first, all separated by %20. Eg. street%20town%20province%20country

Update

I did some reading, you don't need an API key. Here's an explaination.

To get the results, I use jquery.

Here's an example-

$.get('https://maps.googleapis.com/maps/api/geocode/json?address=Scone%20%NSW%20Australia', function(data){
      console.log(data.results[0].geometry.location)
})

The result is an object, containing an array called results. Each array element is a result, containing your coords.

This example logs an object with the coords of Scone, NSW.

JasTonAChair
  • 1,948
  • 1
  • 19
  • 31