Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get user's position in Google maps API?

Tags:

google-maps

I noticed that the google maps api has a option "sensor".

like image 342
lovespring Avatar asked Nov 30 '22 09:11

lovespring


2 Answers

The approach to "get user's position in Google maps" is dependent on which devices you are targeting.

The HTML 5 Approach is meant for Androids, iPhones and other mobile platforms that have support for HTML5. In this case the browser is able to obtain the co-ordinates directly from the GPS without you having to write the code in the native language.

However if you are developing on say QT to target Symbians and the like, you'll need to write the code in the native language (C++ in my case) to acquire the co-ordinates from your GPS and post it to the server to update the user's current location. You'll find details about retrieving co-ordinates using Qt Mobility API here.

like image 26
Philar Avatar answered Jan 22 '23 07:01

Philar


"sensor" in GMaps API is not an option, it is an information parameter. Here is what docs say:

Use of the Google Maps API(s) requires that you indicate whether your application is using a sensor (such as a GPS locator) to determine the user's location in any Maps API library or service requests.

Google Maps doesn't know anything of your users, so it cannot provide their location. It is the other way around: you can determine user's location and give it to Google Maps to place a location pointer and so on.

You have several options to get user's location in JS:

  • W3C (HTML 5) Geolocation API (needs browser support);
  • Google Gears API (needs Google Gears installed);
  • gelocation by IP, for instance, MaxMind and HostIP (the least accurate, but works most of the time).

If you're developing for a sensor-equipped device (like a mobile phone with GPS reciever) there should be some vendor-specific ways to get the location directly from the device.

like image 64
VladV Avatar answered Jan 22 '23 09:01

VladV