I saw all the trouble people were having getting Lat and Lon information and I couldn't get reliable results from geocoder. So I came up with this temporary solution. I don't believe it's against Google's Terms of Use. Someone correct me if I'm wrong.
I just use this function to get the lat and lon and save it into my database. That way I'm not relying on this code to work forever.
I hope it helps someone out and doesn't make Google folks mad.
I have taken your function listed and created a script to pull all of the addresses listed in my database and pass in that address to google, then I take the lat and long and insert those into the database row of that address.
So now I have all the lats, and longs but I dont know how to pull the lat and long from my DB and pass those PHP variables into a Javascript function for the API. Any suggestions would be helpful.
Aaron Silvers wrote: > Nor should it. All you've done at this point is assign values to > $lat and $lng.
> You can echo them immediately after the list( $lat, $lng) and you'll > get results.
> Thanks so much, Cretien, for the code sample. I've transcrbed it > without using fopen, for those of us with webhosts that would rather > one use cURL:
I believe you should be able to open up a javascript page in an iframe, which is generated with php, and simply set two javascript variables, lat and lon, in that iframe.. which your main page can access. That is the no page refresh way of doing it. Otherwise just echo the db results into the javascript function within your page.
You can see an example of dynamic loading on my website http://www.rentnear.com I use this method to dynamically load selects without a page refresh.
nmwe...@gmail.com wrote: > I have taken your function listed and created a script to pull all of > the addresses listed in my database and pass in that address to google, > then I take the lat and long and insert those into the database row of > that address.
> So now I have all the lats, and longs but I dont know how to pull the > lat and long from my DB and pass those PHP variables into a Javascript > function for the API. Any suggestions would be helpful.
> Thanks
> Nathan
> Aaron Silvers wrote: > > Nor should it. All you've done at this point is assign values to > > $lat and $lng.
> > You can echo them immediately after the list( $lat, $lng) and you'll > > get results.
> > Thanks so much, Cretien, for the code sample. I've transcrbed it > > without using fopen, for those of us with webhosts that would rather > > one use cURL:
Here's a Cold Fusion (not PHP) snippet for getting geocodes from Google. I assume it's fairly easy to figure out for whatever language you're using. The snippet below parses the response from google, locates the 'lat=' and 'lng=' pattern in the response string (via regular expressions), then grabs each of the attributes based on their position and length in the string (via the two arrays -- .pos and .len -- returned by REFind. I assume PHP has something similar.)
My CF is a little rusty, so I'm not sure if I needed the <CFOUTPUT> in the final two lines. But it works.
---
(the variable 'addy' here is the actual street address, city, zip -- something like "555 West Hampton, Boone, Iowa, 50601" or whatever)
nmwe...@gmail.com wrote: > I have taken your function listed and created a script to pull all of > the addresses listed in my database and pass in that address to google, > then I take the lat and long and insert those into the database row of > that address.
> So now I have all the lats, and longs but I dont know how to pull the > lat and long from my DB and pass those PHP variables into a Javascript > function for the API. Any suggestions would be helpful.
Remember, PHP executes on the server and can write javascript script that contains the values from PHP. For examples, you can do something like this: