Get a Jumpstart with our Sample Apps
Results 1 to 6 of 6

Thread: Zip Code Lookup in Phone Gap

  1. #1
    Member
    Real Name
    Darol Harrison
    Join Date
    Aug 2011
    Location
    Arkansas
    Posts
    41

    Default 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. #2
    Member
    Real Name
    Jeff Grannis
    Join Date
    Apr 2016
    Location
    New Iberia, LA
    Posts
    125

    Default 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?

  3. #3
    Member
    Real Name
    Darol Harrison
    Join Date
    Aug 2011
    Location
    Arkansas
    Posts
    41

    Default 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.

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,380

    Default 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.

  5. #5
    Member
    Real Name
    Darol Harrison
    Join Date
    Aug 2011
    Location
    Arkansas
    Posts
    41

    Default 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.

  6. #6
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,380

    Default 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.

Similar Threads

  1. Active Phone number on smart phone?
    By kingcarol in forum Mobile & Browser Applications
    Replies: 30
    Last Post: 06-21-2013, 04:02 PM
  2. Zip Code Lookup
    By Dennis22 in forum Alpha Five Version 8
    Replies: 12
    Last Post: 08-18-2008, 07:37 AM
  3. Replies: 10
    Last Post: 08-01-2007, 10:33 PM
  4. Zip Code Lookup Help
    By Jarrett Nahon in forum Alpha Five Version 5
    Replies: 5
    Last Post: 08-28-2003, 07:46 PM
  5. lookup zip code
    By Harold Jacubowitz in forum Alpha Five Version 4
    Replies: 4
    Last Post: 03-06-2001, 12:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •