Discussion Forums  >  Uncategorized

Replies: 19    Views: 339

Yap Attack! Dev Team
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
02/14/11 08:22 PM (15 years ago)

Getting users location in sub-menus

Our app asks the users permission to access fine location when it is run. In the status bar of my Android, on the main screen of our app the location sensor is enabled and the icon shows - which is exactly what we want. However, we use the users location in a javascript diner finder that we added through the buzztouch html/javascript screen. As soon as this screen is accessed, the location sensor in the phone shuts off, preventing us from accessing that fine location. If anyone can tell us how to get the values of the users latitude and longitude and use them in this type of sub-page it would be greatly appreciated. Also, we've experimented with instead having a menu direct a user to a custom google maps url, with parameters preset (in particular, we set it up to perform a specific query every time, theoretically using current location.) If the issue of keeping the location sensor 'on' when we interact with menus in the app can be solved, then theoretically, this query from the url would be relevant. Obviously, this would be more simple than coding the javascript. Thank you for your help, -Dan Yap Attack! Dev Team
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
02/14/11 10:06 PM (15 years ago)
Good questions here. It's tough to say what the best approach would be without more details (like seeing your HTML / Javascript). However, an explanation of how the CustomHTML screen works on Android could help. Also, how the location manager works and why the GPS indicator is on when the home screen is in the forefront. Here's how the GPS works... a) App launches, GPS turns on (indicator shows in status bar) b) While it's on the home screen, the app captures, and remembers the 'last location' c) App leaves home screen, GPS switches off to save battery. Last location is still remembered. d) Home screen is re-visited, GPS goes back on and updates the app's last known location. The latitude and longitude can be access in the Java source code anywhere in the app by asking the app's delegate for this info. LIke this... String lastLatitude = appDelegate.currentDevice.deviceLatitude; String lastLongitude = appDelegate.currentDevice.deviceLongitude; Ok, so how to use this information in the CustomHTML? Understanding how this screen works may provide some clues. a) Menu item is tapped to load a CustomHTML screen b) CustomHTML screen loads and checks to see if it already downloaded the HTML to display (previously cached) c) If data is NOT in the cache, it's downloaded and saved. d) If data IS in the cache, it is 'read' and displayed. This is all happening in the Screen_CustomHTML.java file inside the /src folder. The method that loads the web-view is called: public void loadDataString(String theString); This method takes a passed in string (the HTML downloaded or fetched from the cache) and loads it in the web-view. It easy to imagine doing some sort of find-n-replace on this data before it loads. Example: If the HTML included something special, like a merge-field or something, you could 'merge' the latitude / longitude into the javacript. Example: You may have a javscript function called 'get diners' or something. The URL it fetches could be coded like... getdiners.php?latitude=[latitude]&longitude=[longitude] (see the square brackets, just one approach I'm thinking of as I type. So... in the loadDataString method, you could find-n-replace all occurances of [latitude] and [longitude] with appDelegate.currentDevice.deviceLatitude, etc. I don't know the java method from memory that would accomplish this, just thinking while I type. I hope this makes sense and was some help.
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
02/16/11 12:34 PM (15 years ago)
Thanks David! it helps to have someone like you who can explain how some of the generic function of buzztouch works, its a great help. pointed us in the perfect direction. Another idea/question... in the custom URL section of the buzztouch interface, is it possible to include the users latitude and longitude using a similar calling method? if we cannot do this directly in the URL, would you happen to know which function to manipulate in the source code so that only one of our custom URL's is changed, not all? for example: our main menu contains a button called Diner Finder --> we want to essentially get the users location and search Google Maps to get directions to the 5 closest diners to the user now we have a sub menu containing 3 other custom URL's ---> 1. company's blog 2. company's facebook and 3. company's twitter when we went searching through the custom URL section of the source code (where you've previously pointed us) we attempted to manually concatenate a URL that contained the users location set to variables similar (but not exactly like) to the ones that you just suggested. When we did this, however, it messed up all 4 URLs and none of them executed. Is there a way to individually access the specific URL we want to create?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
02/16/11 01:54 PM (15 years ago)
Glad to hear your 'hacking around' a bit in the source - good stuff. I can think of few ways to do what you're describing. The interface at buzztouch for v1.4 apps doesn't have any of this functionality. v1.5 has tons of it but it' s available for Android yet - sigh. So.. how to do it with your code? One way to do this for ONE url and not the others would be to hard-code some logic to look for a particular string but only in a certain URL. For example, if the ONE URL you wanted to identify was mycoolsite.com/locationfinder.php you could search the URL for locationfinder.php and append something to the end of it, but append nothing to the end of other URLS. This type of logic is already happening in Screen_CustomURL.java. Have a look at the three or for conditional checks that start with if(url.contains('something')) Screen_CustomURL.java is already looking at URLs and identifying the ones that contain youtube.com, .mp3, and .zip. We identify these so these types of files don't open in the app's built in browser but instead open in the Android Native browser. In you case, we would want to identify your special URL so we could append variables to the end of it. Like this... if(url.contains('locationfinder.php')){ //apend latitude and longitude to this variable url = url + 'latitude=' + appDelegate.currentDevice.deviceLatitude + '&longitude=' + appDelegate.currentDevice.deviceLongitude; } Now, the URL has the location attached to the end. In Java, the single quotes are double qoutes, the forum yells about double quotes! Hope this helps.
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
02/17/11 10:39 AM (15 years ago)
David, I wish I was in California so I could buy you a drink! Thank you!
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
02/17/11 02:57 PM (15 years ago)
Unfortunately, the drink might have to wait. So, we went in and hardcoded it, and it seemed promising. However, despite creating an appropriate 'if (url.contains(blah))', it was still launched in buzztouch's built in browser. For fun, we changed the url property on our menu properties screen to a simple youtube url, and miraculously, the native browser opened! We can't seem to figure out why maps.google.com is still launching in the built in browser despite setting nativebrowser to 1. Any help?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
02/17/11 10:23 PM (15 years ago)
Hmm... Email your Screen_CustomURL.java file to info '@' buzztouch.com, along with the URL you are trying to open in the native browser - I'll fix-it-up and shoot it back.
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
03/03/11 12:41 PM (14 years ago)
Just emailed the file! Sorry for the delay, thanks for all your help
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
03/14/11 09:58 PM (14 years ago)
so while you've been working on the file, Ive been messing around testing some other stuff and came to realize (I think) that there is something still overriding our changes to the Screen_CustomURL.java file. I did the test with youtube.. in the conditional statements that youve set up, it essentially says if the custom url contains youtube.com, then use the native browser. so first, I decided to replace youtube.com with google.com in the condition that you set up, since maps.google.com.... is the url we are attempting to load. that clearly didnt work, hence my last question... next, I attempted to invoke a new intent that would open the Google Maps application and send the same query... not a bad idea, possibly even better than opening the native browser, however this had no effect and it still opened our URL in the buzztouch browser and nothing changed. then, in an attempt to test, I put youtube.com back into the conditional, kept the code for the intent to open Google Maps inside that (since I already know that when youtube.com is in the URL, the app recognizes to enter that if statement), and surprisingly the app still new to use the native browser. this is puzzling me because.. no where in this file does it say (anymore) to use the native browser with youtube! now Im even more confused than I was in the first place, I hope you can understand what Im trying to explain here :/
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
03/14/11 10:12 PM (14 years ago)
Giggling. Partly because of your even-more-confused-than-ever comment. Funny. And partly because I FORGET about the file you sent more than a week ago! I looked at it bit that day then botched it and havn't gone back - yikes. I'll get a look NOW and get back. Check this post later - sorry for the delay, my fault completely.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
03/14/11 10:22 PM (14 years ago)
I'm messing with your app, please don't change anything in Karma Cartel. Also, you'll notice the modified date changes, thats me messing around ;-)
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
03/14/11 10:59 PM (14 years ago)
Check your email. All set ;-)
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
03/19/11 10:29 AM (14 years ago)
Thanks David! Android works... now is there just as simple of a solution to do the same thing with Apple? We're kind of in a hurry with this one, we didnt realize the process to get Apple apps onto their marketplace takes much longer than Android does.. and we have to have it done by the end of the week! Deadlines are no fun... Im just not sure of the exact location of the file that you directed us to in the Apple source code, or the syntax or placement within that code to add the conditional statement that you replied. So if you could help us do exactly what you did to our Android code, to our Apple code, it would be very greatly appreciated. Then these two will be done!
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
03/19/11 10:31 AM (14 years ago)
I know we could rebuild it in 1.5 (we tried) but were pressed for time and want there to be some continuity in the layouts of the app across platforms so it would be more convenient to work with what we have in 1.4 now and eventually update both to 1.5 when its available for Android
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
03/19/11 11:22 AM (14 years ago)
Done. Check your email again. I've attached an updated version of the karmacartelclothingAppDelegate.m file. Replace that file in your xcode project with the attachment. If you add a Cusotm URL screen (like the Diner finder) to a menu, the lat/lon of the device will be appended to the end.
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
03/19/11 11:55 AM (14 years ago)
wow that was fast! I replaced the file, build and ran it in xcode on the iPhone simulator and our Diner Finder button (that goes to the custom URL screen) just isnt working. All of the other menu buttons are clickable, but when I click the Diner Finder button.. nothing happens, and the screen remains on the home screen of the app. any ideas?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
03/19/11 12:11 PM (14 years ago)
Nope, I did the same thing an hour ago. At that time it was loading google. Look output the URL to the console maybe? Open the console when you click the link - what URL is it trying to open? I think my notes will read 'Google Maps URL' or something.
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
03/19/11 12:18 PM (14 years ago)
We just tested it in the simulator after commenting out the code you just sent, and without appending any sort of location-aware query to the maps URL (only a request to search for diners) and it worked at our exact location! go figure...
 
Yap Attack! Dev Te...
Aspiring developer
Profile
Posts: 21
Reg: Jan 25, 2011
Rutgers
210
like
03/19/11 02:52 PM (14 years ago)
Hey David, First of all, we just wanted to take a second to thank you for your quick and helpful responses; it's a great motivator in a world of automated help-lines and impersonal error reports ;) So, another quick question. Concerning the Apple version of the app, we have one URL that gives the user the option to open the Maps app. (because the url contains 'maps.google.com' as seen in the CustomURLVIEWController.m file). This seems promising, except we then lose the ability to 'manipulate' the map (we think) because since the maps.google.com trigger immediately reverts to the maps app, it disregards any modifiers (zoom, q=, etc) in the url. Interesting! The other option which we are pursuing now is to have a URL that performs a search in regular old google.com. It seems once again (as in the case of our android app) that the nature of the programming causes the buzztouch browser to initialize, which causes the user to have to click Use current location (which, although only another click, definitely reduces the appeal of the app's functionality). Off the top of your head, is there a magic line of code somewhere that we can change that would prevent the buzztouch browser from ever being considered as an option? Or, at least in the case of checking what strings the URL contains, could we re-program so that any variation of google would open the URL directly in Safari? I'm curious if something could simply be changed in the karmacartelclothingAppDelegate.m script, where it seems that the App is 'geared up' to be used. Anyway, thank you for your time, patience and enthusiasm helping us learn the ways of the force. (or at least App building for now.) -Yapp Attack! Dev. Team
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
03/20/11 12:11 AM (14 years ago)
Learn the force - love that. So, it's tough to consider all the possible angles. This is one of the biggest motivators to keep pushing v1.5 forward. Super hard to continue to evolve 1.4 for the entire group, we basically don't. This is why I don't mind helping you with your 'one off' questions and adjustments. I get it about the iOS / Android support. So get it. You could append whatever you want to the maps.google.com variable for things like zoom level etc. Have a look at the parameters for a Google Map URL (google it). Right now, all the code is doing (in your app) is appending ?q=lat,lon The question mark is important. It's the 'first parameter' flag in a URL. You could easily change this to append an ampersand instead of a question mark if you're needing to use more variables. HOWEVER, the control panel must then have a URL with the question mark. Like this: maps.google.com?q= If you entered that in the control panel, then change your code to append only the lat / lon (after the equals sign) then you could easily do something like... maps.google.com?zoom=wahtever&q= See the difference? You are adding variables in the control panel, then adding the lat/lon 'last' This should work.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.