EasyCFM.COM ColdFusion Forums / Coding Help! / getting longitude and latitude from google maps

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: getting longitude and latitude from google maps

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

megan
09-01-2005 @ 12:41 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

Hi - I would like to retrieve the longitude and the latitude of a location from google maps.

For example, if you use the url:
http://maps.google.com/maps?q=kansas+city

a map will be displayed and on the page will be link that says "link to this page" and that link will contain the longitude and latitude in the url e.g.
http://maps.google.com/maps?q=kansas+city&ll=39.100492,-94.575119&spn=0.121240,0.220482&hl=en
If I try to retrieve the page contents using cfhttp, I get no map data back - I could sign up to use the google maps api, but it requires the longitude and latitude (which I am trying to get from google maps itself - I don't want to have to pay for a service) - I keep thinking this should be simple, but was not as simple as I first thought - any ideas as to how I might proceed?? thanks, megan

We have art so that we shall not die of reality ~ Nietzsche

This message was edited by megan on 9-1-05 @ 9:44 PM

megan
09-01-2005 @ 2:10 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

just as a ps, whether I use "post" with my cfhttp

<cfhttp method="post"
   url="http://maps.google.com/maps?"
     resolveurl="yes">     
     <cfhttpparam name="url_var" type="URL" value="q=kansas+city">
</cfhttp>

or "get"

<cfhttp method="get"
   url="http://maps.google.com/maps?q=kansas+city"
     resolveurl="yes">     
</cfhttp>

if you try it you will see what I mean when I say no map info is returned

<cfoutput>
   #cfhttp.fileContent#
</cfoutput>

thanks for any ideas, megan

We have art so that we shall not die of reality ~ Nietzsche

Webmaster
09-01-2005 @ 2:34 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4542
Joined: Jan 2002

Would you like a free database that contains ll the cities in the US (With Latitude and longtitude?) Will that make things easier? Smile

Pablo Varando
Chief Software Architect
EasyCFM.COM, LLC.

904.483.1457\\ mobile
webmaster@easycfm.com\\email

megan
09-01-2005 @ 3:34 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

Hi Pablo - If I was actually interested in only getting the latitude and longitude of just the cities it would be perfect :D - my goal is actually to snatch the latitude and logitude of actual addresses from google maps insert them into a database for use later in feeding back to the google maps api to generate a map showing that exact location. - but thanks for the thought Smile  I appreciate it, megan

We have art so that we shall not die of reality ~ Nietzsche

megan
09-01-2005 @ 4:04 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

ok - after much digging I found out I can get what I need by adding "&output=js" to my url - this output contains the latitude and longitude info, now I just need to brush up on my regex (Ugh!!) ~megan

We have art so that we shall not die of reality ~ Nietzsche

maquiladoras
09-01-2005 @ 9:29 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2073
Joined: Dec 2002

in the cfhttp.filecontent you actually have
<center lat="x" lng="y">

just the one occurance, all you need to do is find that then isolate it

-
"There is no justice, There is Just Us"
-

megan
09-01-2005 @ 9:35 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

yes, that or <point lat="x" lng="y"/> either one gives me what I was after Smile  thanks, megan

We have art so that we shall not die of reality ~ Nietzsche

maquiladoras
09-01-2005 @ 9:59 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2073
Joined: Dec 2002

megan, this really isn't pretty, but it works
its a modified UDF from cflib.org getTagContent by Johan Steenkamp


<cfscript>
function getStrContent(start, finish, str) {
     var matchStruct = structNew();
     var startTag = "#start#";
     var endTag = "#finish#";
     var endTagStart = 0;
     matchStruct = REFindNoCase(startTag,str,1,"true");
     if(matchStruct.len[1] eq 0 ) return "";
     endTagStart = REFindNoCase(endTag,str,matchStruct.pos[1],"false");
     return Mid(str,matchStruct.pos[1]+matchStruct.len[1],endTagStart-matchStruct.pos[1]-matchStruct.len[1]);
}
</cfscript>

<html>
<head><title>Google Maps Longitude/Latitude Test</title></head>
<body>
  <CFIF IsDefined('form.action')>
   <CFIF form.action IS "get">
    <CFHTTP url="#form.city#" port="80" method="get" resolveUrl="yes" redirect="no">
    <CFSET LongLat= #getStrContent('<center', '>', cfhttp.Filecontent)#>
    <CFSET Latitude = #getStrContent('lat="', '" ', LongLat)#>
    <CFSET Longitude= #getStrContent('lng="', '"/', LongLat)#>
    <cfoutput>
      Latitude = #Latitude#  <br/>
      Longitude = #Longitude# <br/>
    </cfoutput>
   </CFIF>
  </CFIF>

<br/><br/><br/>

<form name="testForm" action="GetLatitude.cfm" method="POST">
Choose a city:
<select name="City">
  <option value="http://maps.google.com/maps?q=kansas+city">Kansas City</option>
  <option value="http://maps.google.com/maps?q=orlando">Orlando</option>
  <option value="http://maps.google.com/maps?q=san+francisco">San Francisco</option>
</select>
<br/>
<input type="hidden" name="action" value="get">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>


hope that might help

-
"There is no justice, There is Just Us"
-


Website Designed and Developed by Pablo Varando.