Page 6 of 8 FirstFirst ... 45678 LastLast
Results 101 to 120 of 141

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: Improving our Coding Skills

  1. #101
    Quote Originally Posted by Dacal View Post
    More simple to use the XML url for Google Maps and do something like this.

    Code:
    function GoogleMaps(coords) {
    			var url = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=" + coords + "&sensor=false";
    			jQuery.get(url, function(data) {
    			obj.address = [];
    			for (var i=0; i <=6; i++) { obj.address[i] = "NO DATA"; }
    			var t=0;
    				$(data).find('result').each( function() {
    					obj.address[t] = $(this).find('formatted_address').text().split(",")[0].replace(/^\s+|\s+$/g,'');
    					t++;
    				});
    			dealwithdata();
    			});
    }
    
    function dealwithdata() {
    			document.getElementById("address0").innerHTML = obj.address[0];
    			document.getElementById("address1").innerHTML = obj.address[1];
    			document.getElementById("address2").innerHTML = obj.address[2];
    			document.getElementById("address3").innerHTML = obj.address[3];
    			document.getElementById("address4").innerHTML = obj.address[4];
    			document.getElementById("address5").innerHTML = obj.address[5];
    			document.getElementById("address6").innerHTML = obj.address[6];    
    }
    THANKS! So - if there's NO data in field 6 - the whole function won't fail? If there's no data in field 6 what will the contents of obj.address[6] say?
    Last edited by NewdestinyX; 04-29-2014 at 01:18 PM.
    Here to help if I can. If I can't I know someone who can!

  2. #102
    Quote Originally Posted by NewdestinyX View Post
    THANKS! So - if there's NO data in field 6 - the whole function won't fail? If there's no data in field 6 what will the contents of obj.address[6] say?
    It will say "NO DATA" .


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  3. The Following 2 Users Say Thank You to Dacal For This Useful Post:

    King_O_Hill (04-29-2014), NewdestinyX (04-29-2014)

  4. #103
    Quote Originally Posted by NewdestinyX View Post
    THANKS! So - if there's NO data in field 6 - the whole function won't fail? If there's no data in field 6 what will the contents of obj.address[6] say?
    If you looked at the code, you would see where he set all fields to No Data and then if data exists, it will get overwritten with actual data. This way there is always something available. To be parsed. This is always a good technique to apply when you run into a situation where you must have data or your code fails. Always pre-populate the data with something generic and you will never have this issue. Coding 101

    Check out WW2 for iOS 8 - Widget-Weather 2.0

  5. The Following 2 Users Say Thank You to King_O_Hill For This Useful Post:

    Dacal (04-29-2014), NewdestinyX (04-29-2014)

  6. #104
    Quote Originally Posted by Dacal View Post
    It will say "NO DATA" .
    Thanks - EXCEPT -- see below. No data of any kind is being returned with the code you gave me, bro.. Test yourself. Nothing's being returned...

    Quote Originally Posted by King_O_Hill View Post
    If you looked at the code, you would see where he set all fields to No Data and then if data exists, it will get overwritten with actual data. This way there is always something available. To be parsed. This is always a good technique to apply when you run into a situation where you must have data or your code fails. Always pre-populate the data with something generic and you will never have this issue. Coding 101
    First - I 'always' look at the code. Just because a line or two is still Greek to me - doesn't mean I didn't look at it, Bri.. Some times you say things in the 'azz-iest' ways, bro.. Sheesh..

    This program shows no results for address[0] as coded. Why not?

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <html>
    <head>
    <style>
    @font-face {font-family: "Segoe WP Light";  src: url('Segoe WP Light.ttf');}
    
    body{
    position:absolute;
    width:320px;
    height:60px;
    top:0px;
    left:0px;
    margin:0;
    padding:0;
    opacity: 1.0;
    }
    
    #address0{
    position:absolute;
    z-index:0;
    top:0px;
    left:0px;
    width:309px;
    height:255px;
    line-height:60px;
    color: white;
    font-family:Segoe WP Light;
    text-shadow: 0 3px 6px #000, 0 3px 6px #000;
    }
    </style>
    
    </head>
    
    <body bgcolor="transparent" onload="init()">
    
    <div id="address0"></div>
    
    <script>
    function GoogleMaps(coords) {
    var url = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=" + "40.114851, -75.210054" + "&sensor=false";
    	jQuery.get(url, function(data) {
    	obj.address = [];
    	for (var i=0; i <=6; i++) { obj.address[i] = "NO DATA"; }
    	var t=0;
    	$(data).find('result').each( function() {
    		obj.address[t] = $(this).find('formatted_address').text().split(",")[0].replace(/^\s+|\s+$/g,'');
    		t++;
    		});
    	dealwithdata();
    	});
    }
    
    function dealwithdata() {
    	document.getElementById("address0").innerHTML = obj.address[0];
    	document.getElementById("address1").innerHTML = obj.address[1];
    	document.getElementById("address2").innerHTML = obj.address[2];
    	document.getElementById("address3").innerHTML = obj.address[3];
    	document.getElementById("address4").innerHTML = obj.address[4];
    	document.getElementById("address5").innerHTML = obj.address[5];
    	document.getElementById("address6").innerHTML = obj.address[6];   
    }
    </script>
    
    </body>
    </html>
    Assume I've put the font file in the same folder with my Widget.html containing the above code..
    Last edited by NewdestinyX; 04-29-2014 at 04:27 PM.
    Here to help if I can. If I can't I know someone who can!

  7. #105
    Quote Originally Posted by NewdestinyX View Post
    Thanks - EXCEPT -- see below. No data of any kind is being returned with the code you gave me, bro.. Test yourself. Nothing's being returned...

    First - I 'always' look at the code. Just because a line or two is still Greek to me - doesn't mean I didn't look at it, Bri.. Some times you say things in the 'azz-iest' ways, bro.. Sheesh..

    This program shows no results for address[0] as coded. Why not?

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <html>
    <head>
    <style>
    @font-face {font-family: "Segoe WP Light";  src: url('Segoe WP Light.ttf');}
    
    body{
    position:absolute;
    width:320px;
    height:60px;
    top:0px;
    left:0px;
    margin:0;
    padding:0;
    opacity: 1.0;
    }
    
    #address0{
    position:absolute;
    z-index:0;
    top:0px;
    left:0px;
    width:309px;
    height:255px;
    line-height:60px;
    color: white;
    font-family:Segoe WP Light;
    text-shadow: 0 3px 6px #000, 0 3px 6px #000;
    }
    </style>
    
    </head>
    
    <body bgcolor="transparent" onload="init()">
    
    <div id="address0"></div>
    
    <script>
    function GoogleMaps(coords) {
    var url = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=" + "40.114851, -75.210054" + "&sensor=false";
    	jQuery.get(url, function(data) {
    	obj.address = [];
    	for (var i=0; i <=6; i++) { obj.address[i] = "NO DATA"; }
    	var t=0;
    	$(data).find('result').each( function() {
    		obj.address[t] = $(this).find('formatted_address').text().split(",")[0].replace(/^\s+|\s+$/g,'');
    		t++;
    		});
    	dealwithdata();
    	});
    }
    
    function dealwithdata() {
    	document.getElementById("address0").innerHTML = obj.address[0];
    	document.getElementById("address1").innerHTML = obj.address[1];
    	document.getElementById("address2").innerHTML = obj.address[2];
    	document.getElementById("address3").innerHTML = obj.address[3];
    	document.getElementById("address4").innerHTML = obj.address[4];
    	document.getElementById("address5").innerHTML = obj.address[5];
    	document.getElementById("address6").innerHTML = obj.address[6];   
    }
    </script>
    
    </body>
    </html>
    Assume I've put the font file in the same folder with my Widget.html containing the above code..
    First, where is the init function you call in the body tag ? Second, put the script part in the head section, Third, don't forget to load the jquery plugin .

    See below.

    <?xml version="1.0" encoding="UTF-8"?>
    <html>
    <head>
    <style>
    @font-face {font-family: "Segoe WP Light"; src: url('Segoe WP Light.ttf');}

    body{
    position:absolute;
    width:320px;
    height:60px;
    top:0px;
    left:0px;
    margin:0;
    padding:0;
    opacity: 1.0;
    }

    #address0{
    position:relative;
    z-index:0;
    top:0px;
    left:0px;
    width:309px;
    height:20px;
    color: white;
    font-family:Segoe WP Light;
    text-shadow: 0 3px 6px #000, 0 3px 6px #000;
    }


    #address1{
    position:relative;
    z-index:0;
    width:309px;
    height:20px;
    color: white;
    font-family:Segoe WP Light;
    text-shadow: 0 3px 6px #000, 0 3px 6px #000;
    }

    #address2{
    position:relative;
    z-index:0;
    width:309px;
    height:20px;
    color: white;
    font-family:Segoe WP Light;
    text-shadow: 0 3px 6px #000, 0 3px 6px #000;
    }

    #address3{
    position:relative;
    z-index:0;
    width:309px;
    height:20px;
    color: white;
    font-family:Segoe WP Light;
    text-shadow: 0 3px 6px #000, 0 3px 6px #000;
    }

    #address4{
    position:relative;
    z-index:0;
    width:309px;
    height:20px;
    color: white;
    font-family:Segoe WP Light;
    text-shadow: 0 3px 6px #000, 0 3px 6px #000;
    }

    #address5{
    position:relative;
    z-index:0;
    width:309px;
    height:20px;
    color: white;
    font-family:Segoe WP Light;
    text-shadow: 0 3px 6px #000, 0 3px 6px #000;
    }

    #address6{
    position:relative;
    z-index:0;
    width:309px;
    height:20px;
    color: white;
    font-family:Segoe WP Light;
    text-shadow: 0 3px 6px #000, 0 3px 6px #000;
    }
    </style>
    <script type="text/javascript" charset="utf-8" src="jquery.min.js"></script>
    <script>
    var obj = new Array;

    function init() {
    GoogleMaps();
    }

    function GoogleMaps() {
    var url = "http://maps.googleapis.com/maps/api/geocode/xml?latlng=40.114851,-75.210054&sensor=false";
    jQuery.get(url, function(data) {
    obj.address = [];
    for (var i=0; i <=6; i++) { obj.address[i] = "NO DATA"; }
    var t=0;
    $(data).find('result').each( function() {
    obj.address[t] = $(this).find('formatted_address').text().split("," )[0].replace(/^\s+|\s+$/g,'');
    t++;
    });
    dealwithdata();
    });
    }

    function dealwithdata() {
    document.getElementById("address0").innerHTML = obj.address[0];
    document.getElementById("address1").innerHTML = obj.address[1];
    document.getElementById("address2").innerHTML = obj.address[2];
    document.getElementById("address3").innerHTML = obj.address[3];
    document.getElementById("address4").innerHTML = obj.address[4];
    document.getElementById("address5").innerHTML = obj.address[5];
    document.getElementById("address6").innerHTML = obj.address[6];
    }
    </script>

    </head>

    <body bgcolor="transparent" onload="init()">

    <div id="address0"></div>
    <div id="address1"></div>
    <div id="address2"></div>
    <div id="address3"></div>
    <div id="address4"></div>
    <div id="address5"></div>
    <div id="address6"></div>

    </body>
    </html>
    Last edited by Dacal; 04-29-2014 at 04:42 PM.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  8. #106
    Quote Originally Posted by Dacal View Post
    First, where is the init function you call in the body tag ? Second, put the script part in the head section, Third, don't forget to load the jquery plugin .
    I've never needed to load a JQuery plugin in TacoHTMLEdit for Mac before.. JQuery just works whenever I use it.. What do you mean? Can you just post the correct version of the simple widget and I'll learn from it?
    Here to help if I can. If I can't I know someone who can!

  9. #107
    Done

    See above.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  10. #108
    Thanks, my friend! I had already figured the init call before you wrote back. But is the JQuery plugin that jquery.min.js file?

    I'm still not getting any readout in my preview pane..

    Is this what my folder should look like?

    Last edited by NewdestinyX; 04-29-2014 at 05:20 PM.
    Here to help if I can. If I can't I know someone who can!

  11. The Following User Says Thank You to NewdestinyX For This Useful Post:

    Dacal (04-29-2014)

  12. #109
    Quote Originally Posted by NewdestinyX View Post
    Thanks, my friend! I had already figured the init call before you wrote back. But is the JQuery plugin that jquery.min.js file?

    I'm still not getting any readout in my preview pane..

    Is this what my folder should look like?

    It is if that's how you are calling it from your HTML.

    <code>
    <script type="text/javascript" charset="utf-8" src="jquery.min.js"></script>
    </code>
    Last edited by King_O_Hill; 04-29-2014 at 05:40 PM.

    Check out WW2 for iOS 8 - Widget-Weather 2.0

  13. The Following 2 Users Say Thank You to King_O_Hill For This Useful Post:

    Dacal (04-29-2014), NewdestinyX (05-01-2014)

  14. #110
    Quote Originally Posted by King_O_Hill View Post
    It is if that's how you are calling it from your HTML.

    <code>
    <script type="text/javascript" charset="utf-8" src="jquery.min.js"></script>
    </code>
    I used Dacal's code from two posts ago exactly as he wrote it. Which showed no folder assignments for the JQuery plug-in js file or the font. So that's my folder with Dacal's exact code from his edited post right before mine. Syntax checker in my editor shows everything as being perfect with no errors. And I still have no readout in the preview pane. I don't believe Google's API XML format is functional. I think Ras told us something about that before and that's why he preferred the JSON.

    Can you run Dacal's code on your editor, Brian, and see if it works for you. You don't even need the font file. You can take the call for it out completely and it'll still be fine.
    Here to help if I can. If I can't I know someone who can!

  15. #111
    Quote Originally Posted by NewdestinyX View Post
    I used Dacal's code from two posts ago exactly as he wrote it. Which showed no folder assignments for the JQuery plug-in js file or the font. So that's my folder with Dacal's exact code from his edited post right before mine. Syntax checker in my editor shows everything as being perfect with no errors. And I still have no readout in the preview pane. I don't believe Google's API XML format is functional. I think Ras told us something about that before and that's why he preferred the JSON.

    Can you run Dacal's code on your editor, Brian, and see if it works for you. You don't even need the font file. You can take the call for it out completely and it'll still be fine.
    Hi NewD,

    I have tested. Works fine.
    -mmi.png


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  16. The Following User Says Thank You to Dacal For This Useful Post:

    NewdestinyX (05-01-2014)

  17. #112
    Quote Originally Posted by Dacal View Post
    Hi NewD,

    I have tested. Works fine.
    -mmi.png
    Dacal, I'm confused by your screenshot of your editor. At the bottom of the screen I see that my address was written as part of the div tag. Why was that necessary if we're trying to get data from an API?

    Why did you change the code line to this:
    Code:
    <div id="address0">6340 Arlingham Road"</div>
    ???!?
    Last edited by NewdestinyX; 04-29-2014 at 06:52 PM.
    Here to help if I can. If I can't I know someone who can!

  18. #113
    Hi NewD, it's not an editor : it's Chrome on my computer. I don't have put the address between the tag, it was automatically added with the "document.getElementById("address0").innerHTML = obj.address[0];" .
    Last edited by Dacal; 04-29-2014 at 07:17 PM.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  19. The Following User Says Thank You to Dacal For This Useful Post:

    NewdestinyX (05-01-2014)

  20. #114
    Quote Originally Posted by Dacal View Post
    Hi NewD, it's not an editor : it's Chrome on my computer. I don't have put the address between the tag, it was automatically added with the document.getElementById function .
    In the code itself?? I've never seen a div tag get text added to it from a URL call in an editor software.. But I don't use Chrome. The code still doesn't work for me on any of my computers.. I'm puzzled.. It's written exactly as you send it to me. Still stumped. Thank you for your time, my friend!
    Here to help if I can. If I can't I know someone who can!

  21. The Following User Says Thank You to NewdestinyX For This Useful Post:

    Dacal (04-29-2014)

  22. #115
    Quote Originally Posted by NewdestinyX View Post
    In the code itself?? I've never seen a div tag get text added to it from a URL call in an editor software.. But I don't use Chrome. The code still doesn't work for me on any of my computers.. I'm puzzled.. It's written exactly as you send it to me. Still stumped. Thank you for your time, my friend!
    Nevermind NewD, it's just the way you see things in chrome console.

    And on your phone ?
    Last edited by Dacal; 04-29-2014 at 07:51 PM.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  23. The Following User Says Thank You to Dacal For This Useful Post:

    NewdestinyX (05-01-2014)

  24. #116
    Quote Originally Posted by Dacal View Post
    Nevermind NewD, it's just the way you see things in chrome console.

    And on your phone ?
    ALL GOOD NOW!!!!! On my Editor.. When I copied and pasted from MMI this is what happened in the URL code line..

    Code:
    var url = "http://maps.googleapis.com/maps/api/geocode/xml latlng=" + coords + "&sensor=false";
    A 'space' between 'xml' and 'latlng'.. It did NOT paste the '?' from my clipboard... SOOOO STRANGE!!!!! As soon as I added it --- xml?latlng... IT WORKED!!

    Thanks again, Dacal!! I learn so much from you!!! Now I might be able to finish my widget when I need address 6..

    The only problem I still see is that my whole dealWithLocation VERY LONG section of code - uses - obj.zero = formatted.address[0], obj.two, obj.three, etc.. Can I change your code there to give the variable names I'm used to? It doesn't seem obvious to me HOW to do it.. from the i++ method you're using..
    ------------------
    EDITED: No worries. I figured it out. For my uses I need to do this in the last section of the code where you use documentGetElementById:
    Code:
    obj.zero = obj.address[0];
    obj.one = obj.address[1].split("," )[0].replace(/^\s+|\s+$/g,'');
    obj.two = obj.address[2].split("," )[0].replace(/^\s+|\s+$/g,'');
    obj.three = obj.address[3].split("," )[0].replace(/^\s+|\s+$/g,'');
    obj.four = obj.address[4].split("," )[0].replace(/^\s+|\s+$/g,'');
    obj.five = obj.address[5].split("," )[0].replace(/^\s+|\s+$/g,'');
    if (obj.address[6] != 'NO DATA') {
       obj.six = obj.address[6].split("," )[0].replace(/^\s+|\s+$/g,'');
    } else { obj.six = "";
    }
    
    function dealwithdata() {
    document.getElementById("address0").innerHTML = obj.zero;
    document.getElementById("address1").innerHTML = obj.one;
    document.getElementById("address2").innerHTML = obj.two;
    document.getElementById("address3").innerHTML = obj.three;
    document.getElementById("address4").innerHTML = obj.four;
    document.getElementById("address5").innerHTML = obj.five;
    document.getElementById("address6").innerHTML = obj.six; 
    }
    I think that will allow the rest of my code to stay the same. You think?
    Last edited by NewdestinyX; 04-29-2014 at 08:23 PM.
    Here to help if I can. If I can't I know someone who can!

  25. The Following User Says Thank You to NewdestinyX For This Useful Post:

    Dacal (04-30-2014)

  26. #117
    Quote Originally Posted by NewdestinyX View Post
    ALL GOOD NOW!!!!! On my Editor.. When I copied and pasted from MMI this is what happened in the URL code line..

    Code:
    var url = "http://maps.googleapis.com/maps/api/geocode/xml latlng=" + coords + "&sensor=false";
    A 'space' between 'xml' and 'latlng'.. It did NOT paste the '?' from my clipboard... SOOOO STRANGE!!!!! As soon as I added it --- xml?latlng... IT WORKED!!

    Thanks again, Dacal!! I learn so much from you!!! Now I might be able to finish my widget when I need address 6..

    The only problem I still see is that my whole dealWithLocation VERY LONG section of code - uses - obj.zero = formatted.address[0], obj.two, obj.three, etc.. Can I change your code there to give the variable names I'm used to? It doesn't seem obvious to me HOW to do it.. from the i++ method you're using..
    ------------------
    EDITED: No worries. I figured it out. For my uses I need to do this in the last section of the code where you use documentGetElementById:
    Code:
    obj.zero = obj.address[0];
    obj.one = obj.address[1].split("," )[0].replace(/^\s+|\s+$/g,'');
    obj.two = obj.address[2].split("," )[0].replace(/^\s+|\s+$/g,'');
    obj.three = obj.address[3].split("," )[0].replace(/^\s+|\s+$/g,'');
    obj.four = obj.address[4].split("," )[0].replace(/^\s+|\s+$/g,'');
    obj.five = obj.address[5].split("," )[0].replace(/^\s+|\s+$/g,'');
    if (obj.address[6] != 'NO DATA') {
       obj.six = obj.address[6].split("," )[0].replace(/^\s+|\s+$/g,'');
    } else { obj.six = "";
    }
    
    function dealwithdata() {
    document.getElementById("address0").innerHTML = obj.zero;
    document.getElementById("address1").innerHTML = obj.one;
    document.getElementById("address2").innerHTML = obj.two;
    document.getElementById("address3").innerHTML = obj.three;
    document.getElementById("address4").innerHTML = obj.four;
    document.getElementById("address5").innerHTML = obj.five;
    document.getElementById("address6").innerHTML = obj.six; 
    }
    I think that will allow the rest of my code to stay the same. You think?
    Welcome NewdestinyX.

    Yes, it will work, but personnaly i always try to make the code shorter. It would be better if you change the variable names in the rest of your code to the new names.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  27. The Following User Says Thank You to Dacal For This Useful Post:

    NewdestinyX (04-30-2014)

  28. #118
    Quote Originally Posted by Dacal View Post
    Welcome NewdestinyX.

    Yes, it will work, but personnaly i always try to make the code shorter. It would be better if you change the variable names in the rest of your code to the new names.
    Thanks, David. But that would be hundreds of variables to change in my final code now. Too many chances for error.. Unless there's a batch change text software you can apply to .js files..?!
    Here to help if I can. If I can't I know someone who can!

  29. #119
    Quote Originally Posted by NewdestinyX View Post
    Thanks, David. But that would be hundreds of variables to change in my final code now. Too many chances for error.. Unless there's a batch change text software you can apply to .js files..?!
    I use notepad++ on windows, don't lnow if there is a mac version. Lot of options/plugins.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  30. The Following 2 Users Say Thank You to Dacal For This Useful Post:

    NewdestinyX (05-01-2014), RKO1195 (05-01-2014)

  31. #120
    + 1 on the notepad it's great for windows with chrome we are set

  32. The Following User Says Thank You to RKO1195 For This Useful Post:

    NewdestinyX (05-01-2014)

Page 6 of 8 FirstFirst ... 45678 LastLast
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •