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

Zip Code Lookup in Phone Gap

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

    Zip Code Lookup in Phone Gap

    I was trying different things with Phone Gap and created a simple UX control with the Zip Code Lookup Action JavaScript. It works great on my computer, but when I put it on my phone using Phone Gap it does not work. It is apparently not connecting to get the information. I am on wifi and have no other problems with my phone. Any ideas?

    #2
    Re: Zip Code Lookup in Phone Gap

    Put the URL for All Ajax Callbacks that you configured in your PhoneGap settings directly into a web browser on the phone. Is the web browser finding the address (ie. hitting the web server/app server)?
    Do you see the default page for that URL? Or maybe some other http status message?

    Comment


      #3
      Re: Zip Code Lookup in Phone Gap

      I can get to the website (USPS Tools Zip Code Lookup) from my phone's browser. Since the app works on my computer I don't see why the phone wouldn't do the same. I appreciate the questions and will dig deeper into the phone gap settings, which is where I am assuming the issue lies.

      Comment


        #4
        Re: Zip Code Lookup in Phone Gap

        I wouldn't bother with that action for a PhoneGap Build app as it makes a callback to the Alpha server. I'd prefer to go directly to USPS and use their API.

        Go here... https://www.usps.com/business/web-to...is/welcome.htm and Register for a Username.

        Then you can make a call directly to USPS and get back the data you want.

        Supplying Address, City, State... you should get back xml like this... which includes Zip5 and Zip4.

        Code:
        "<?xml version="1.0" encoding="UTF-8"?>
        <AddressValidateResponse><Address ID="1"><Address2>8 WILDWOOD DR</Address2><City>OLD LYME</City><State>CT</State><Zip5>06371</Zip5><Zip4>1844</Zip4></Address></AddressValidateResponse>"
        Code:
        var address = {dialog.Object}.getValue('Address');
        var city = {dialog.Object}.getValue('City');
        var state = {dialog.Object}.getValue('State');
        
        var zipURL = 'http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="YOUR_USERNAME_GOES_HERE"><Address ID="1"><Address1></Address1><Address2>' + address + '</Address2><City>' + city + '</City><State>' + state + '</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>';
        
        fetch(zipURL).then(function(response) {
        	if (response.status !== 200) {
        		console.log('Looks like there was a problem. Status Code: ' +
        		response.status);
        		return;
        	}
        	return response.text();
        }).then(function(text) {
        		var zip = jQuery(text).find("Zip5").text();
        		{dialog.Object}.setValue('Zipcode',zip,false);
        
        }).catch(function(err) {
        	console.log('Fetch Error :-S', err);
        });
        This works under PhoneGap Build in iOS and Android. You'd need to add a bit more error checking in case no Zip comes back.

        Comment


          #5
          Re: Zip Code Lookup in Phone Gap

          Thanks David. I will try what you have provided. My main interest was trying to understand if there was something I was doing wrong on the phone gap build for when I put the real app out there. The zip code one was my test case. It is my understanding the action javascript goes to the USPS web site direct so I expected it to work on the phone app. Appreciate the effort and what you have provided will be a good training effort for me.

          Comment


            #6
            Re: Zip Code Lookup in Phone Gap

            I don't think the Action Javascript makes a direct call to USPS. Open the dialog where that Action Javascript is defined... not the action itself where you define it's parameters, but just where the call is. You have a Radio Button at the top labelled Action Javascript... which is selected. Now... select the other Radio Button choice... Text mode. This turns the Action into code. You'll see that an ajax callback is being made to an XBasic function named "ZipCodeLookup". I don't know where that is... or what it does... it's not documented... but it is an XBasic function of a callback.

            So... you're going from Client - to Server - to USPS - to Sever - to Client.

            This Action does work for me... so your problem could be...

            You have not published your UX to your Alpha Server.

            You have security turned on for your server... but you're not logging in... or your UX security is set to always denied. Most of the time, security for a PhoneGap Build app, should be set to Always Allowed for the UX.

            Your Alpha PhoneGap Build builder property "URL For All Ajax Callbacks" is not set... or not set properly.

            Comment


              #7
              Re: Zip Code Lookup in Phone Gap

              David,

              I'm trying to implement your code in a standard UX component for a browser based component (not Phonegap or mobile) and I when I debug the JavaScript I get an error that fetch is not defined. Is this a PhoneGap framework method and if so is there an equivalent way to accomplish this call for a regulare web-based client?
              Brad Weaver, President
              ComputerAid International
              Ottawa ON Canada
              Versailles KY USA
              www.compuaid.com

              Comment


                #8
                Re: Zip Code Lookup in Phone Gap

                Nope... the fetch API is built into the browser... do a search... you'll find some interesting info about it. You've not detailed what version/build of Alpha your using or the browser version/build... fetch hasn't always been around. You could use XMLHttpRequest instead. I just tried that previously posted code and it runs without error under Chrome and Edge.

                Comment


                  #9
                  Re: Zip Code Lookup in Phone Gap

                  As an alternative, why not use the Google auto-suggest field type which returns loads of info including the zip code?
                  NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                  Comment


                    #10
                    Re: Zip Code Lookup in Phone Gap

                    Originally posted by CharlesParker View Post
                    As an alternative, why not use the Google auto-suggest field type which returns loads of info including the zip code?
                    That sounds interesting... could you provide a bit of detail on how/where to use it?

                    Comment


                      #11
                      Re: Zip Code Lookup in Phone Gap

                      Sure, I first went into the actual builder for it and realized I needed some additional fields in the database because truly it returns ALOT of information and since it is based on the users location (or can be) as the user types in teh address and clicks it ALL of the returned info goes into the other fields, including geocodes!
                      So in my use case, a user gets a phone call and wants to enter in the address - this makes it VERY easy. I can then use the geocodes for mapping purposes.
                      I don’t know if that answers your question, but that is how I use it. It’s just a text field. Since I now use that I no longer have to make the extra call for the zip code it’s already there.
                      NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                      Comment


                        #12
                        Re: Zip Code Lookup in Phone Gap

                        Thanks, guys. Building on David's JavaScript code, I created an Xbasic callback function that's working well now with the new API.

                        Here's sample code (assuming you have fields named Mailing_Address, City, State, Postal_Code in your UX.

                        Code:
                        function PostOffice as c (e as p)
                        	
                        dim Response as c = ""
                        dim ResponseTimeout as n = 30000 '30 seconds
                        dim WebURI as c
                        dim content as p
                        dim vczip as c = ""
                        dim vplus4 as c = ""
                        dim USPS_Zipcode_Lookup2 as c
                        
                        WebURI= "http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID=%22YourUSPSUserID%22><Address ID=%221%22><Address1></Address1><Address2>%20"
                        WebURI = WebURI+alltrim(e.dataSubmitted.mailing_address)+"</Address2><City>"+alltrim(e.dataSubmitted.city)+"</City><State>"+alltrim(e.dataSubmitted.state)+"</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>"
                        
                        Response = http_post_page2(WebURI,"",.f.,ResponseTimeout)
                        *property_from_xml(response,content,.t.)
                        
                        IF eval_valid("content.AddressValidateResponse.Address[1].Zip5[1].__A5_elementContent")
                        	vczip = content.AddressValidateResponse.Address[1].Zip5[1].__A5_elementContent
                        END IF
                        	
                        IF eval_valid("content.AddressValidateResponse.Address[1].Zip4[1].__A5_elementContent")
                        	vplus4 = content.AddressValidateResponse.Address[1].Zip4[1].__A5_elementContent
                        END IF
                        
                        USPS_Zipcode_Lookup2 = ""
                        
                        if vczip = ""
                        	resultmsg = "Could not locate address.  No change made"
                        else
                        	if vplus4 = ""
                        		USPS_Zipcode_Lookup2= vczip
                        	else
                        		USPS_Zipcode_Lookup2= vczip+"-"+vplus4
                        	end if
                        	resultmsg = "Address found.  Postal code has been verified."
                                e._set.postal_code.value = USPS_Zipcode_Lookup2
                        end if
                        PostOffice = "alert('"+resultmsg+"');"
                        
                        END FUNCTION
                        Brad Weaver, President
                        ComputerAid International
                        Ottawa ON Canada
                        Versailles KY USA
                        www.compuaid.com

                        Comment

                        Working...
                        X