LiveCode & google maps...

Peter Brigham MD pmbrig at gmail.com
Tue Feb 15 15:34:22 EST 2011


On Feb 15, 2011, at 11:57 AM, Devin Asay wrote:

>
> On Feb 15, 2011, at 8:56 AM, Peter Brigham MD wrote:
>
>> On Feb 15, 2011, at 8:41 AM, John Dixon wrote:
>>
>>>
>>> Could some please point me in the right direction...
>>>
>>> I
>>> would like to use the browser object in a stack to display a google
>>> map… that I can do. I would like to be able to choose a postcode or
>>> the
>>> name of a town or village from a list in a field in the stack to  
>>> place
>>> the two markers, showing the start and finish location, get the
>>> direction drawn on the google map and the total distance put into
>>> another field in the stack...
>>>
>>> If someone could point me in the
>>> the right direction (no pun intended !) of how to go about doing  
>>> this
>>> from within LiveCode… it would be appreciated as I don't know really
>>> where to start..
>>
>> Here is a function I have used to fetch the total distance between  
>> two
>> addresses from Google maps. The function returns the distance without
>> displaying any map, but you could play with the script to also  
>> display
>> the map.
>>
>> --------
>>
>> function getMileage
>>   put "http://maps.googleapis.com/maps/api/directions/xml?" & \
>>          "origin=<tOrig>&destination=<tDest>&sensor=false" into tURL
>>   put fld "from" into tStart
>>   put fld "to" into tEnd
>>   replace "<tOrig>" with urlEncode(tStart) in tURL
>>   replace "<tDest>" with urlEncode(tEnd) in tURL
>>   put URL tURL into t
>>   put lineoffsets("<distance>",t) into startSect
>>   put item -1 of startSect into startSect
>>   put lineoffsets("</distance>",t) into endSect
>>   put item -1 of endSect into endSect
>>   if startSect = 0 or endSect = 0 then
>>      beep
>>      exit to top
>>   end if
>>   put line startSect+1 to endSect-1 of t into tSect
>>   put lineoffset("<text>",tSect) into dLine
>>   if dLine = 0 then
>>      beep
>>      exit to top
>>   end if
>>   put sr(line startSect + dLine of t) into tMiles
>>   --   <text>3.6 mi</text>
>>   replace "<text>" with empty in tMiles
>>   delete word -1 of tMiles
>>   return tMiles
>> end getMileage
>
>
> Peter,
>
> Thanks for sharing this code. Can you tell us what format the origin  
> and distance argument values need to be in? City, State, Country?  
> Postal Code?
>
> Devin

Look at the Google API. I just paid attention to the case of inputting  
addresses -- other values might be do-able. I didn't check out the  
alternative, but the API seems pretty informative.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig





More information about the Use-livecode mailing list