Mobile GPS web application - php

I need to develop a web app. (PHP) 100% for mobile phones and need to get the information from the mobile phone GPS, in order to get the user's current position. My question is, what should I do?
I know PHP but I'm completely clueless about the GPS part (never worked with them before). All i'm looking is for headsup to see if I can handle the job or just reject it.
I've heard that the W3 geolocation API does a very good job but after testing it i'm not convinced about the accuracy and browser support. I don't want to use Google's gears due to the fact that it must be downloaded first.

I do think the W3C Geolocation API is a good place to start: it has growing acceptance on mobile phones, is an open standard and abstracts away all the device-specific APIs.
It's true that the accuracy may not be perfect, but that's because the phone itself may not always know perfectly where it is. The API gives you a couple ways to work around this: if you need high accuracy, you can hint to the device that you want an accurate result even at the cost of power/time with the enableHighAccuracy flag and set a long timeout parameter to allow the device to use GPS to find a location. Also, all positions are returned with an accuracy value for 95% confidence -- if the error is too high (often phones will return a high error on the first request), you can request the location again, specifying that you don't want a cached location.

It depends on the device but some mobile app frameworks have done all the work for you and have Extensions to do this, check out jqTouch for the iPhone:
http://jqtouch.com/
More specifically:
http://code.google.com/p/jqtouch/wiki/Extensions

GPS coords are available with javascript - place something like this on page load:
function locationHandler(location)
{
var lat = location.coords.latitude;
var lng = location.coords.longitude;
if(lat && lng)
{
// something clever goes in here
}
}
if(typeof navigator.geolocation.getCurrentPosition == 'function')
{
navigator.geolocation.getCurrentPosition(locationHandler);
}
where the comment is where you want to do something clever. you might populate form values, or do an ajax call to a back end script.
Link that in with some reverse geo-coding from Google and you're onto a winner!!

Depending on the mobile device, you may have access to GPS. However, in the broad spectrum of mobile, you probably can not reliably get it from the device's browser alone. Reading the IP would be futile considering the architecture of cellular networks.
It can be done, but you would need to build in level of degradation.

Related

Google Map API download map

my question for professionals I think may be stupid but I had a problem which regards to search for my solution for my problem. Technically I am developing social networking site and I want to integrate Google Map API and my question is, is there any way that I can download the crop image so that it stores to my server so that my web server doesn't need to request to Google Server again. If not, can you give an alternative solution that may fit to may problem and If yes can you give a hint or tip which it could possibly usable to my development process. I am newly in such Web API. Thank you. Regards
try to use something like this
<img src="https://maps.googleapis.com/maps/api/staticmap?center=-15.800513,-47.91378&zoom=11&size=200x200&sensor=false">
will look like
Using the static map api it will return you an img, then you can save it easily as a normal image, but my recomendation is just to have columns with the user's location stored in your database, the address or the coordinates (lat,lng).
Later on when you want to display the map just request it from google using the staticmap or the javascript v3 API.
Advantages:
You save bandwidth and storage space
Easier maintaining of your database and or files structure
Google's server probably has better response time and speed than yours
More dynamic: reverse-geocoding the location or using the coordinates you can display the static map, the normal map (which is not hard, I can tell you), Street View, Google earth and probably a lot of other stuff
You are not going against the Rules
Disadvantages:
Google's daily limits, which are up to 2500 or 1000 requests per day and 10 per second, you can look it up I don't remember. But, if you use tha JavaScript v3 to display the map, the prints are counted on the browser, so it would be 1000(in the worst case) prints per browser(per ip actually), so that means that each user can print 1000 maps per day. It's not really a problem, if your site gets that many views you are doing great xD

Detect mobile devices - and tablet devices

I am currently looking at some code for PHP detection of mobiles, which is probably quite easy.
Now I just have got one problem - I want to make it possible to make unique view-files in my MVC-framework for tablets, mobiles and web pages. So I need to split the tablet from the rest of the mobile devices.
Currently this is the code, that I am using:
public function isMobile()
{
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|sagem|sharp|sie-|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
return true;
else
return false;
}
But this is not enough - the only check is wheter the device is a mobile device - if not it is as standard telling the framework, that we're on a computer. The last part is ok - but I want to make a split of the mobile devices in actual mobiles - and in a secound group, which should be tablets.
I hope, that I have made my wish clear, and I hope, that you have some input in a good way to achieve this.
Thanks in advance.
Here is a class with methods for detecting each platform individually.
https://github.com/serbanghita/mobile-detect
Old question, but here goes my opinion regarding mobile detection.
You state in your question that you want unique files for mobile devices, so I can assume the reason for this is to present a different version of the website for mobile clients and desktop clients.
This approach is OK until a certain point. And that point is called Android. There are ~1.5 million Android devices activated each day with resolutions from 320*240 to 2560*1600, which makes it hard to if {} else for each of them. Even if you try to make a list with most used devices and you try to target only those, it will be hard to support a new device in the future.
My approach a while back was to forget about old method of splitting devices into "mobile" and "desktop" categories and create a new method. And that method consist in "good" and "bad" browsers which is based on browser capabilities. For example, if the browser supports local storage, it will be in "good" category.
Starting from this, I had the possibility to create a "base" version of the website, very basic from a UI standpoint but which will work cross-browser. This base version of the website will present the same content (because that matters at the end of the day) on all devices, will be very small in size (less assets, smaller html) and based on browser capabilities will be enriched on the client side.
So in the end you will end up with a website that has very small footprint (html size and assets), that looks OK cross browser and it will support any new device that comes up on the market without any changes, will load fast even on poor connections and that can be enriched on client side based on browser capabilities.
You can even enrich the webpage based on devices size: if the browser reports a large screen, you can bring in more assets, more ads and make the webpage more beautiful ; if the browser reports is on a small screen, you leave it as is.
Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. — Read more
http://mobiledetect.net
You can also use a more comprehensive solution like WURFL Cloud, which is a service that detects the capabilities of mobile devices, like is_mobile and is_tablet. There is a free plan for low traffic sites: http://www.scientiamobile.com/cloud

Recommend a web service that handles location within a specific radius?

We have a client that wants a store locator on their website. I've been asked to find a webservice that will allow us to send a zipcode as a request and have it return locations within x radius. We found this, but it's maintained by a single person, and doesn't look like it gets updated or supported very well. We're looking for something commercial, ideally that updates their zipcode database at least once per quarter, and that has a well-documented API with PHP accessibility. I won't say price isn't an object, but right now we just want some ideas, and my google-fu has failed me.
I've already posted this over on the webmasters forum, but thought I'd cover my bases and post here too.
I've repurposed this outstanding script to conquor this same challenge. It's free, has been very reliable, and is relatively quick.
In my script, I have addresses stored in the DB. So rather than show a page to enter addresses, I simply pass them as a string and let the magic happen.
He says it in the app, but ensure that if you go this route you get your own Google Maps API. It won't work with his!
If you want to go a bit less technical approach, here's a MySQL query you could run on your locations (you'd have to add lat/long to your DB or setup a GEOCODING service) to give you distance as the crow flies.
Google Maps has a geocoder as well and it geocodes to the specific address.
It's limited to x number of requests but that shouldn't be a big deal if your site is small and if you cache. You can get more requests if you pay.
It can be accessed via javascript or via PHP (and there are several prewritten PHP modules out there)
Link here:
http://code.google.com/apis/maps/documentation/javascript/v2/services.html
(I worked for a company that did upwards of 800,000 requests a day, so it's stable and fast :) )
PostcodeAnywhere has a Store Locator feature - I think it's pay per use, but I've used their other products before and they're very cheap.
http://www.postcodeanywhere.co.uk/store-locator-tool/

What is the best approach to geo targeting?

Lately geo-targeting has been pretty popular in technology. By IP, cell tower, GPS, using browser plugins, HTML5?, mobile devices ...
Since I'm about to add some geo-targeted features on our site, I wanted to know what's the best approach. Is there some API that uses a mix of all those technologies? Or at least, what API/service would you recommend I use?
The service I'm working on doesn't need to be 100% accurate, so I'm OK with geo-IP, but if there's an easy way to do better, why not.
Technologies used are php, javascript, ajax, java.
Whatever you do please please please don't set the language of your website based on the user's IP, and then make it almost impossible to change unless you know said language and you feel like wasting hours (like ebay and paypal, among others, do). Use the browser's language.
Not everyone in, let's say, France speaks or wants to speak French.
I guess it's not very related to your question but i felt the need to rant about this, sorry :)
GEO IP is probably the best approach for now.
HTML5 looks promising, but it'll be a while before it's widely supported. And even then it requires explicit user approval, which kind of limits the possibilities for using it (for example auto-redirecting to a country specific version of a website)
For a start try the free http://api.hostip.info?ip=x.x.x.x (www.hostip.info for website)
It'll give you city and country in a xml structur. I've a small proxy-script writen in PHP on the http-server, which a html page calls with ajax and show the infomation in text and on a Google map using the Google geocoding api. Later on you can easy replace the api.hostip.info with an other api.
I would use IP address detection by default, and then optionally ask for a more specific location using the Javascript/HTML5 navigator.geolocation API when present. (For example, in iPhone Safari)
Most users are still using devices that don't know the location themselves, so plugins that are available will not get a better location than IP address detection does anyway. (Alternatively, they'll prompt users to manually enter data, which is annoying)
Max Mind is good. But if you are looking for a free solution, you may want to consider using the javascript geocoder. Eventually they will support addresses and country, but right now, they only give you a latitude and longitude.

show google map markers with php

Hi everyone!
Im working on a google map project where the user can type in a address and gets the result of nearby restaurants ploted on a google map.
So far no problems. I've created a ajax call where the backend outputs and xml and then with jquery I create the markers.
But now to my problem.
With this ajax solution anyone can easily with firebug or other webdeveloper tool access the xml result that contains all names, latitudes, longitudes of the restaurant I have.
I want to somehow protect the data that is showed.
How can I do this?
How can I plot google map markers with php without jquery? Can it be done?
thx in advance!
Google Maps Markers for an interactive map (using a the GMap2 object in the API) must be created on the client side (in Javascript) and are therefore vulnerable to reverse engineering the data.
If you want to generate the map data on the server, then you are limited to static functionality on the client. You can use the Google Static Maps API to build a URL on the server, which includes the information about the markers you want to display and the region that the static map will show. This approach sacrifices some usability for the client (no dynamic zooming, panning, marker popups etc...) to protect your data.
N.B. A determined engineer will still be able to access your data (albeit with some difficulty) by:
Parsing your static maps URL to determine the map region
Analyzing the image data to find markers and determine their locations.
The only way to protect the data is to render the map before sending it to the browser. Doing that will take most or all the cool features of google maps away since you'd have to display just an image.
Any data that is accessable by google maps is accessable by someone with firebug.
Some things you can do to make life difficult for someone trying to grab your data:
In your server code, examine the headers to see if the request came from your client page. If the request came from anywhere else, return nothing.
Encode the data that you return from the server. Decode it as late as possible in your client code, so that you only have the plaintext for one restaurant in Javascript variables at any one time. That way someone with Firebug can only directly read one restaurant at a time.
Have your server only return a limited number of locations at once, even if somebody uses Firebug to change the request parameters so that it asks for restaurants within a huge radius. That way they can only grab the cyphertext for that many locations at once to paste into their own code in which they've placed a copy of your decoding function.
Instead of grabbing the cyphertext for even that limited number of locations in a single call, send multiple requests that each return a very small number of locations, with an extra parameter specifying which chunk of restaurants is requested.
Its not foolproof, but for someone to grab substantial quantities of your data will either take them a long time, or require fairly sophisticated attack techniques, such as spoofing the request headers.
Simple answer - you can't.
Long answer
You could draw an image overlay on server-side, kinda like Wikipedia overlay in Google maps, but I don't think it's worth the effort.
You could also store a key in php session and pass it to JavaScript on initial page load and then don't return the data if data isn't requested trough Ajax with the correct key (which is unique per browser session). This would just protect you from simple bots which don't support cookies. More mess then gain.
Also remember that if someone were to write competing site using your server as data-source then they would still have to tunnel Ajax requests trough their own server because you can't do cross-domain requests with JavaScript therefore you would see a lot requests from same IP (their web-server) in your web-logs and you could easily ban that IP. (Unless they download all at once and then serve from their own server).
And is it really necessary? It's not like restaurant locations are top secret.

Categories