Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Anyone reverse Geocoded - say lang/lat delivers Address

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Anyone reverse Geocoded - say lang/lat delivers Address

    Hi everyone, just wondering - have a need to determine the address or location from the longitude latitude or the geocode done it in a dialog that would help me out? Just thought i'd ask before heading down the discovery path. Best regards to all for the coming holiday season just a month away.
    Last edited by peteconway; 11-18-2012, 09:50 PM.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

    #2
    Re: Anyone reverse Geocoded - say lang/lat delivers Address

    Pete, you may have figured this out already and I know addresses likely read differently in Austrailia than the US, but I put this together for my own use this afternoon and thought I'd share.

    Code:
    FUNCTION geoAddrFromLatLon AS P (lat AS C, lon AS C )
    
    string = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lon + "&sensor=false"
    
    jsonReq = http_get(string)
    
    jsonBody = json_parse(jsonReq.body)
    fullAddress = jsonBody.results.[1].formatted_address
    
    dim addr as P
    addr.Street = word2(fullAddress,1,",")
    addr.City = word2(fullAddress,2,",")
    addr.State = substr(word2(fullAddress,3,","),2,2)
    
    geoAddrFromLatLon = addr
    
    END FUNCTION

    Comment


      #3
      Re: Anyone reverse Geocoded - say lang/lat delivers Address

      Thanks for thinking of me Chris, I got stuck on a few other issues and this one slipped a bit - was just going to re visit it. Good timing - will give it a go and come back to you. Best wishes for the coming holiday season mate.
      Insanity: doing the same thing over and over again and expecting different results.
      Albert Einstein, (attributed)
      US (German-born) physicist (1879 - 1955)

      Comment


        #4
        Re: Anyone reverse Geocoded - say lang/lat delivers Address

        This works fantastic!!
        Chad Brown

        Comment


          #5
          Re: Anyone reverse Geocoded - say lang/lat delivers Address

          Thanks very much, will be adapting for the UK

          Comment


            #6
            Re: Anyone reverse Geocoded - say lang/lat delivers Address

            Glad you all got something from it.

            Just a follow-up note that you may not get an exact address, which is probably assumed, but Google actually returns an address range sometimes (e.g. 1000-1040 Main Street), so I later made a less-than-ideal-but-safer modification to get the average address value in the range if that's the case:

            Code:
            FUNCTION geoAddrFromLatLon AS P (lat AS C, lon AS C )
            
            string = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lon + "&sensor=false"
            
            jsonReq = http_get(string)
            
            jsonBody = json_parse(jsonReq.body)
            fullAddress = jsonBody.results.[1].formatted_address
            
            dim addr as P
            addr.Street = word2(fullAddress,1,",")
            
            streetNum =word2(addr.Street,1," ")
            if like("*-*",streetNum)
            	street =  stritran(addr.Street,streetNum,"")
            	streetNum1 = convert_type(word2(streetNum,1,"-"),"N")
            	streetNum2 = convert_type(word2(streetNum,2,"-"),"N")
            	streetNum = convert_type(((streetNum1 + streetNum2)/2),"C")
            	addr.street = streetNum + " " + street
            end if
            
            addr.City = word2(fullAddress,2,",")
            addr.State = substr(word2(fullAddress,3,","),2,2)
            addr.Zip = stritran(word2(fullAddress,3,","),addr.State + " ","")
            
            
            geoAddrFromLatLon = addr
            
            END FUNCTION
            Also, in terms of your design, I found that when called from a component via an ajax callback, the location functions only work if the component is on an a5w page (i.e. not called on a "virtual page" via javascript).

            Comment


              #7
              Re: Anyone reverse Geocoded - say lang/lat delivers Address

              You are a good man Chris, thanks.
              Insanity: doing the same thing over and over again and expecting different results.
              Albert Einstein, (attributed)
              US (German-born) physicist (1879 - 1955)

              Comment


                #8
                Re: Anyone reverse Geocoded - say lang/lat delivers Address

                God knows the vast majority of my application is slight variants on code and ideas I got from others on the forum, yourselves included. Thought I'd go one step further: http://screencast.com/t/2jCTfbE5P.

                I lied. The button calls an Action Javascript Geolocation Functions function that fills in hidden fields with the latitude and longitude. Then an onChange Event on the latitude field calls the ajax callback that takes it from there.
                Last edited by christappan; 04-23-2013, 11:41 PM. Reason: I lied.

                Comment


                  #9
                  Re: Anyone reverse Geocoded - say lang/lat delivers Address

                  Good on mate - thanks - teaching and learning is what this forum is about.
                  Insanity: doing the same thing over and over again and expecting different results.
                  Albert Einstein, (attributed)
                  US (German-born) physicist (1879 - 1955)

                  Comment


                    #10
                    Re: Anyone reverse Geocoded - say lang/lat delivers Address

                    Originally posted by peteconway View Post
                    Good on mate - thanks - teaching and learning is what this forum is about.
                    That's a good one Pete, how about those great videos you made, care to share?
                    Regards
                    Keith Hubert
                    Alpha Guild Member
                    London.
                    KHDB Management Systems
                    Skype = keith.hubert


                    For your day-to-day Needs, you Need an Alpha Database!

                    Comment


                      #11
                      Re: Anyone reverse Geocoded - say lang/lat delivers Address

                      Gee mate that was a long time ago now, i'll have to think about it, I am for all to move towards Alpha Anywhere after the success I've had with it, so showing old methods may just cause problems.
                      Insanity: doing the same thing over and over again and expecting different results.
                      Albert Einstein, (attributed)
                      US (German-born) physicist (1879 - 1955)

                      Comment


                        #12
                        Re: Anyone reverse Geocoded - say lang/lat delivers Address

                        Hi, I am a total newbie, and am working on a mobile app that, when a button is pushed, I would like to get the current location from the device, then geocode that lat/long into an address as in the function given in this thread. Then, I would like to take that address info and present it to the user and have them confirm that the address is accurate before saving the lat/long to the database. Could someone please help me with this. I already have the code retrieving the current location from the device, but I am struggling to figure out how to pass that information to the xBasic function and get the result.

                        Thanks in advance for any help,

                        Jim M.



                        Originally posted by christappan View Post
                        Glad you all got something from it.

                        Just a follow-up note that you may not get an exact address, which is probably assumed, but Google actually returns an address range sometimes (e.g. 1000-1040 Main Street), so I later made a less-than-ideal-but-safer modification to get the average address value in the range if that's the case:

                        Code:
                        FUNCTION geoAddrFromLatLon AS P (lat AS C, lon AS C )
                        
                        string = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lon + "&sensor=false"
                        
                        jsonReq = http_get(string)
                        
                        jsonBody = json_parse(jsonReq.body)
                        fullAddress = jsonBody.results.[1].formatted_address
                        
                        dim addr as P
                        addr.Street = word2(fullAddress,1,",")
                        
                        streetNum =word2(addr.Street,1," ")
                        if like("*-*",streetNum)
                        	street =  stritran(addr.Street,streetNum,"")
                        	streetNum1 = convert_type(word2(streetNum,1,"-"),"N")
                        	streetNum2 = convert_type(word2(streetNum,2,"-"),"N")
                        	streetNum = convert_type(((streetNum1 + streetNum2)/2),"C")
                        	addr.street = streetNum + " " + street
                        end if
                        
                        addr.City = word2(fullAddress,2,",")
                        addr.State = substr(word2(fullAddress,3,","),2,2)
                        addr.Zip = stritran(word2(fullAddress,3,","),addr.State + " ","")
                        
                        
                        geoAddrFromLatLon = addr
                        
                        END FUNCTION
                        Also, in terms of your design, I found that when called from a component via an ajax callback, the location functions only work if the component is on an a5w page (i.e. not called on a "virtual page" via javascript).

                        Comment


                          #13
                          Re: Anyone reverse Geocoded - say lang/lat delivers Address

                          I just delivered exactly this to a customer Jim. This is some of the Xbasic in my AJAX Callback - see if it helps:

                          Code:
                          	' Use Google API for reverse geolocation:
                          	'https://developers.google.com/maps/documentation/geocoding/
                          	' See section on "Reverse Geocoding"
                          	dim p as P
                          	url = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=" + vlat + "," + vlon + "&sensor=false"
                          	p = http_get(url)
                          	result = p.body
                          	beginstr = "<formatted_address>"
                          	endstr = "</formatted_address>"
                          	paddress = extract_string(result, beginstr, endstr)
                          	paddress = stritran(paddress, ", USA")
                          	e._set.device_street_address.value = paddress
                          -Steve
                          sigpic

                          Comment


                            #14
                            Re: Anyone reverse Geocoded - say lang/lat delivers Address

                            Not sure how you're populating the latitude and longitude in your component, but I hid those fields. Then, in their onChange event, I created an Ajax Callback taht simply called a function called getAddrFromCurrLoc.

                            In the XBasic functions, I have this:
                            Code:
                            function getAddrFromCurrLoc as c (e as p)
                            
                            lat = e.dataSubmitted.Latitude
                            long = e.dataSubmitted.Longitude
                            
                            if lat <> "" .and. long <> ""
                            	address = geoAddrFromLatLon(lat,long)
                            
                            	e._set.mi_street.value = address.street
                            	e._set.mi_city.value = address.city
                            	e._set.mi_state.value = address.state
                            	e._set.mi_zip.value = address.zip
                            
                            	getAddrFromCurrLoc = "{dialog.Object}.setValue('LATITUDE','');{dialog.Object}.setValue('LONGITUDE','');"
                            else
                            	getAddrFromCurrLoc = ""
                            end if
                            So when the value changes in the latitude or longitude field, this ajax callback runs and fills in the mi_street field, mi_city field, mi_state field, mi_zip fields in the component. This was written for a Dialog component but the grid would be very similar.

                            Steve,
                            I wanted to point out that you're doing almost the same thing I did in my code and may be handling errors differently, but you might want to note how I chose to handle Google returning inexact addresses.

                            Comment


                              #15
                              Re: Anyone reverse Geocoded - say lang/lat delivers Address

                              First, I would like to thank christappan and Steve Workings for your replies. These both helped a ton.

                              Now that I have my test component (attached here MySampleComponent.a5wcmp) retrieving the current location (automatically via the Action JavaScript "Ajax Callback Action"), I have a new question:

                              Q: When I run this component, and allow location services to work, I get the lat/long returned into the text boxes on the UX, but the other named elements (defined via HTML in the static text definitions) do not get updated to the address values. Can someone explain why? The code I have was derived from a video I watched, as well as from the prototype code itself. I am very confused.

                              Another odd behavior:

                              In my Xbasic function, I have the following statement:

                              if e.__locationFound = .t.

                              When I execute this code in my browser, it ALWAYS falls through to the "else" statement, regardless of whether or not I allow the location to be given. If I remove the " = .t." from the statement, then the component works as expected when I allow the location to be given, but throws an error "e.__locationLatitude subelement not found" when I deny location services. Now I am REALLY confused.

                              Thanks in advance!!!

                              P.S. Although I am very new to Alpha, I am already really impressed with what it can do, and how easy it is.
                              Last edited by jmarciniak; 11-01-2013, 05:23 PM. Reason: added the "Another odd behavior" section

                              Comment

                              Working...
                              X