iPhone Transmitting CoreLocation over the Internet - objective-c

Alrighty, let's try this again!
I'm currently developing an application that will be relying on a web server for some of its functionality. I'm interested, however, in transmitting the user's location to other users who request it. What would be the best possible way to implement this in the application? Thank you! :D

If I were making this application for a standard linux server, I would have a MySQL table called locations, or users. Inside that table, I would store the device id, the latitude, longitude, and date of the users' location. Then, when a user's location changes, update the entry in the table using a HTTP request to a PHP script.
As far as the programming, look into NSURLRequests and NSURLConnections. You would need to do a POST or GET, including this information. This might be an example of the requests:
{ /* Update Location: http://hostname/path/location.php */
action = "updatelocation",
deviceid = "635262f796d3fe35229275d5835bf42861c33f23",
latitude = 0,
longitude = 0
}
Processing on the server wouldn't be too hard. That should at least get you started on storing the locations. Letting other users request the locations would be a little harder.

Related

How to store custom user data on Netlify Identity?

I've been using Netlify for storing 100% of my app (both frontend and backend) for the last three months. So far, so good.
The only problem now is that I need to store a custom property for each user (say, the phone number), and apparently Netlify Identity doesn't support this (only email, name and roles https://www.netlify.com/docs/identity/).
I don't want to change the whole app to migrate to another hosting provider just for this detail (actually, I can't, it's for a client and I just don't have time), because it works great, but at the same time I need it.
Can you think of any workaround to this? The less "hackish", the better, but I understand that I'm going beyond the intended use of Netlify Identity.
So it actually does look like Netlify's GoTrue API has a specific endpoint for updating custom user data. After a user is created, you can update metadata by including it as "data" within an authenticated PUT request to /user.
PUT /user
{
"data" {
"custom_key": "value",
}
}
See https://github.com/netlify/gotrue for more info.
There are dozens of ways to do this, so I'll talk about two generally applicable ways now:
the most "generally capable" one is probably using lambda functions: https://www.netlify.com/docs/functions . This lets you run dynamic code, such as "store to database hosted elsewhere" or "email to our office manager to update a spreadsheet" or even "commit to our closed git repo so it's available in-code" (last one is probably a worst practice, but is possible). You can similarly use a function to read that data back out without exposing API tokens (code example: https://github.com/netlify/code-examples/tree/master/function_examples/token-hider)
you could have the data gathered via a form submission (https://www.netlify.com/docs/form-handling). I'd probably use zapier.com to receive a notification of the form submission (https://www.netlify.com/docs/form-handling/#notifications). Zapier can of course connect to just about anything on the planet :) . Getting the data back out if you want to show it in your UI is a bit more of a challenge, but you could use the above mentioned functions if you need to connect to some private data store to pull it out. Or for an MVP, just not show it, only let people enter/update it ;)

How can i add some score stored in a variable to a SQL database from a SWF? - AS3

I have a game in SWF with AS3 that scores points and stores it on a variable called "Puntos". Here's how I'm doing it:
stop();
var puntos:int = new int();
add_puntos.addEventListener(MouseEvent.CLICK, agregar);
function agregar(event:MouseEvent):void
{
puntos=puntos+3;
puntos_txt.text=String(puntos);
trace(puntos);
}
Now, i have to take the result of the variable "puntos" and add it to the absolute score of the player on a SQL Database. ¿How can i do it? :(
UPDATE: Thanks Andrey. Effectively, it's not for mobile. I'm going to try it :)
You need backend knowledge in order to save those scores (or if you are working on a mobile - at least SQL knowledge).
The client part is easy - sending a simple POST request to the server, where all the magic happens. You can see the examples here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html#includeExamplesSummary
If you are working on a mobile - things get harder, and you would need go search Google instead :)
Edit: Having in mind you are using mobile device, this is for you: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118676a5497-7fb4.html

Where to store data in Sencha Touch?

I have following case to handle:
My mobile application ( Sencha Touch App wrapped in native container ) has around 5000 book titles. Now, I don't want application to ping server to get these books on his mobile. Application will need to access this data during run time. So should I
a) dump the data into sqlite at the time of installation of the application ? (First time run)
b) Fetch data from files only. ( I will be making sorting and querying operations over this data - may not be a good solution if I store the entire file in an array at once and process it further )
Kindly advice.
Create a JSON API to fetch your data from a database on the server.
You can store this data in JSON file and then use JSON proxy to load/sort/query it.
BUT its better to expose a web service, just like what Diodeus said.

Using JSON to update app's content in iOS

I'm about to create an application that uses JSON to update its content.
This is how I planned it to work:
When application starts, it checks (with internet connection is available) if the JSON file set on remote server is newer than the one stored localy - if it is then it's downloaded.
Then, the application applies data from that JSON to the content. For example, to the "Contact" information - it applies data like phone numbers etc.
My question is, is it in your opinion, a good technique to update appliactions content?
Does anynone had an experience with building app with this kind of idea?
Best regards,
Zin
Of course you can do this. One thing that may lead to a better user experience would be to ask the user for his permission to download new content (if there is something new).
This is a normal thing to do. I have a phonebook app that does exactly this. On a side note, if you need a network class to handle the web-service interaction, see this SO post. I wrote a custom network class that works with AFNetworking.

REST API for driving distance?

Is there a service that will give me the driving distance between two addresses? Apparently Google Maps API requires you to display a map, which I don't want to do (on that particular page), and I'd like to just snag the data and save it to my DB after a user submits a form, rather than waiting for JS to do it's thing.
If it's relevant, this is going into a Django app. I discovered that CloudMade offers a Python API, which is nice, except their latest dev release has a bug in it (can't use the API object), but more importantly, it's support for Canada is awful (couldn't find directions from any major city around here!).
MapQuest's Directions API is HTTP Querystring based (I'm not sure if it's entirely RESTful). Can get XML or JSON response. Just need to send it an HTTP GET Request.
http://developer.mapquest.com/web/products/open/directions-service
Use the "distance" response parameter.
I don't have a high enough reputation on SO to comment on an answer but I just wanted to be clear that contrary to the voted correct answer, Google Directions API has to adhere to the Google Maps API. If you scroll down the supplied link, you will see:
Note: the Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited. Additionally, calculation of directions generates copyrights and warnings which must be displayed to the user in some fashion. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions.
Would it be possible to use Google Maps GDirections object? This can return the textual directions instead of the map overlay if called with a div object. From there you can use the getDistance (or getDuration) functions. You can always use an invisible div for the returns if you don't want anything to be displayed on the page.
Start here
http://code.google.com/apis/maps/documentation/examples/directions-advanced.html
http://code.google.com/apis/maps/documentation/reference.html#GDirections
And use this sample code
var map;
var directionsPanel;
var directions;
function initialize() {
directionsPanel = document.getElementById("route");
directions = new GDirections(null, directionsPanel);
GEvent.addListener(directions , "load", onGDirectionsLoad);
directions.load("from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)");
}
function onGDirectionsLoad(){
alert(directions.getDistance().html);
}
Here is my solution:
Signup for Mapquest Developer network.
Get AppId
Open your command shell and run the following command(or use fiddler) But running it through curl will give you flexibility to automate your request
curl -X POST -H "Content-Type: application/json" -d '{locations: ["Salt Lake City, UT","Ogden, UT",],options: {allToAll: false}}' http://www.mapquestapi.com/directions/v2/routematrix?key=YOURKEYGOESHERE >> distance.txt
Save above command with all your destinations into batch or sh file.
Now grep and parse out your distance.txt file for what you need.
There are free services out there, but the quality of the data may be questionable/non-existent in areas. Be aware of licences on the data too, storing in your own DB may be a breach.
http://openrouteservice.org/
Take a look at Navteq. I used their service in developing a driving directions application about 5 years ago, and got good results. Can't speak for them lately though. I believe the best URL is Navteq Routing Service
You can use the new Google Directions API directly, without using any javascript.
http://code.google.com/apis/maps/documentation/directions/