lovespring
lovespring

Reputation: 19559

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

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

Upvotes: 4

Views: 22331

Answers (5)

Billel Hacaine
Billel Hacaine

Reputation: 157

The sensor parameter is no longer required. from here:

The Google Maps API previously required that you include the sensor parameter to indicate whether your application used a sensor to determine the user's location. This parameter is no longer required.

Upvotes: 0

sebilasse
sebilasse

Reputation: 4618

For google maps API v3 it is described here: https://developers.google.com/maps/documentation/javascript/basics

Upvotes: 0

stewe
stewe

Reputation: 42612

Another way to get the user's position is to include:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

in your page.

This creates a javascript object "google.loader.ClientLocation" which contains the user's latitude, longitude and address.

Example:

google.loader.ClientLocation = {
    "latitude": 51.817,
    "longitude": 19.3,
    "address": {
        "city": "Aleksandrow Lodzki",
        "region": "Lodz",
        "country": "Poland",
        "country_code": "PL"
    }
};

Upvotes: 3

VladV
VladV

Reputation: 10349

"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:

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.

Upvotes: 14

Philar
Philar

Reputation: 3897

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.

Upvotes: 3

Related Questions