Getting a Google MAP

Devin Asay devin_asay at byu.edu
Thu Apr 27 17:41:26 EDT 2017


Bill,

As Mike mentioned, the API call returns image data, so set the filename of an image to the url. Here’s the script from a working demo:

on mouseUp
    put urlEncode(fld "address") into tAddress
    put urlEncode(fld "city") into tCity
    put urlEncode(fld "state") into tState

    put the thumbposition of scrollbar "scale" into tScale
    put the hilitedButtonName of group "maptype" into tType
    put "http://maps.google.com/maps/api/staticmap" into tBaseURL
    put  "?center=" into tArgList
    if tAddress is empty then
        --put empty into tArgList
    else
        put tAddress & comma after tArgList
    end if
    put tCity & comma & tState after tArgList
    put "&zoom=" & tScale & "&size=512x512&maptype=" & tType after tArgList

    # build marker
    put urlEncode(fld "m_address") into tMAddress
    put urlEncode(fld "m_city") into tMCity
    put urlEncode(fld "m_state") into tMState
    put the label of btn "color" into tMColor
    put toUpper(char 1 of fld "label") into tMLabel
    put "&markers=" & "color:" & tMColor & "|label:" & tMLabel & "|" & tMAddress,tMCity,tMState after tArgList

    put tBaseURL & tArgList into fld "urlfld"
    set the filename of img "map" to fld "urlfld"
end mouseUp

Most of the script is building a URL string with the proper arguments. The last two statements are where you actually display the image.

One thing I will say its that if you want to use it for other than just occasional demos, you will have to register with Google for an API key, when gets tacked on to the end of the argument list for the URL.

If you’d like you can grab the working stack here (from the message box):

go stack URL "http://dight310.byu.edu/lesson_materials/14-Web_services/googleMaps.livecode"

Hope this helps.

Devin


On Apr 27, 2017, at 2:49 PM, William Prothero via use-livecode <use-livecode at lists.runrev.com<mailto:use-livecode at lists.runrev.com>> wrote:

Folks:
Turns out there is a Google Static Map api. I’m trying to use it, but get no response from my code that indicates an error.
The Static Maps API URL is: https://developers.google.com/maps/documentation/static-maps/?csw=1 <https://developers.google.com/maps/documentation/static-maps/?csw=1>

From the dictionary, it looks like I can do this: (this is the example in the google docs. It gives me a map when I put the URL into the browser).
on mouseUp

 put mapURL() into tURL

 put tURL

  put URL tURL into x

  put x into image  “myGMap” —This, obviously won’t work. See below.

end mouseUp


function mapURL

   put "https://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&key=AIzaSyCO423QzwaEEBmiw4XjPKzz4Tcg_5bjHv4" into retURL

    return retURL

end mapURL

I get text back that looks like that below. It is obviously in some format I can decode in Livecode. I’ve just reached my comfort level with this. How should I decode this. so I can set the imagedata to it?
Tnx,
Bill P

—start of returned text
âPNG



���
IHDR��ê��ê���∑a∆˛��ùPLTE<84{<,KKKLLLNNNSPLPPPRRRTTTVVVYYY^^^aaabbbdddfffkgchhhmmmssstttxxxzzz4®S�õ⁄BÖÙDÑÚEÜÚIäÒNäÚOçÚPçÚSèÚTêÚXíZíÛYîÙaóÙbòıjùÙmûıt£Û{•}™Úó{WãocÍC5ËD8ËE:ÈG9ÈJ:ÈL?


_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com<mailto:use-livecode at lists.runrev.com>
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Devin Asay
Director
Office of Digital Humanities
Brigham Young University



More information about the use-livecode mailing list