
Obtaining Correct Response From Google Geolocation Api For Mac
The Geolocation API of HTML5 helps in identifying the user’s location, which can be used to provide location specific information or route navigation details to the user.
Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.
There are many techniques used to identify the location of the user. A desktop browser generally uses WIFI or IP based positioning techniques whereas a mobile browser uses cell triangulation, GPS, A-GPS, WIFI based positioning techniques, etc. The Geolocation API will use any one of these techniques to identify the user’s location.
The Geolocation API protects the user’s privacy by mandating that the user permission should be sought and obtained before sending the location information of the user to any website. So the user will be prompted with a popover or dialog requesting for the user’s permission to share the location information. The user can accept or deny the request.
Now let us first understand the API and then plot your location in the Google Maps.
The first step in using any of the APIs in HTML5 is to check for its compatibility with the browser.
Check for Browser compatibility
The geolocation property of the global navigator object helps in detecting the browser support for the Geolocation API.
Get the user’s current location
The current location of the user can be obtained using the getCurrentPosition
function of the navigator.geolocation
object. This function accepts three parameters – Success callback function, Error callback function and position options. If the location data is fetched successfully, the success callback function will be invoked with the obtained position
object as its input parameter. Otherwise, the error callback function will be invoked with the error
object as its input parameter.
- Success callback function
This callback function is invoked only when the user accepts to share the location information and the location data is successfully fetched by the browser. The location data will be available as a position object and the function will be called with the position object as its input parameter. A position object contains atimestamp
property denoting the time at which the location data is retrieved and acoords
object.The
coords
object has the following properties- Latitude, longitude – Geographic coordinates in decimal degrees
- Accuracy – Accuracy level of the latitude and longitude coordinates in meters. Bigger the number lesser is the accuracy
- Altitude – Height of the position above the sea level in meters
- AltitudeAccuracy – Denotes how far off the altitude position could be from the actual attitude value obtained in meters. Bigger the number lesser is the accuracy
- Heading – Provides 360 degree heading information
- Speed – Indicates relative speed in meters per second
- Error callback function
This is an optional callback function that takes a ‘Position Error’ object as its input parameter. This function is invoked under any one of the following circumstances- Unknown Error occurred
- Request timed out
- User has denied to share the location information
- Location information itself is unavailable
- Position Options
It describes the options to use while retrieving the user’s location.
- enableHighAccuracy: Boolean. If true, the user agent will try to provide the most accurate position. This can result in slower response time and higher power consumption. Is false, less accurate position will be obtained. Default value is false.
- Timeout: Positive long value. It denotes the maximum time (in milliseconds) that the user agent can take to respond with the location data. Default value is Infinity.
- maximumAge: Positive long value. It denotes how long (in milliseconds) the user agent can keep using the cached location data before trying to obtain new location data. A zero value indicates that the user agent must not use the cached location data and infinity value indicates that the cached location data must be used by the user agent.
Track Location changes
The watchPosition()
can be used to get the location data at regular intervals. The success callback function is invoked automatically as and when the device or the useragent position changes. The parameters to this function is similar to the getCurrentPosition()
function. It returns a watch ID
value which can be used to unregister the success callback function by passing it to the clearWatch()
function.
Show My Location on Google Maps
In order to plot your location on Google Maps we can make use of Google Maps API along with Geolocation API.
- First of all, we should convert the latitude and longitude coordinates of the position object obtained using the Geolocation API into a Google maps
latLng
object. - Create a Map object specifying the map display options and the HTML div container where the map should be displayed. In the example below three map display options are specified
- Zoom – Specifies the zoom level
- Center – Specifies that the map should be centered at the user location
- mapTypeId – Can be Roadmap, Satellite or Hybrid
- Create a marker at the location as given below
In the above code marker options indicate the following
- Map – Map object where the marker should appear
- Position – latlng position at which the marker should be displayed
- Title – Title that should appear when we hover on the marker
- Find the address of your location using the reverse geocoding API and show the address obtained when you click on the marker.
Sample Code
Conclusion
Start exploring Google maps API and see what more features you can build on top of the sample given above.
The W3C Geolocation API is an effort by the World Wide Web Consortium (W3C) to standardize an interface to retrieve the geographical location information for a client-side device.[1] It defines a set of objects, ECMAScript standard compliant, that executing in the client application give the client's device location through the consulting of Location Information Servers, which are transparent for the application programming interface (API). The most common sources of location information are IP address, Wi-Fi and BluetoothMAC address, radio-frequency identification (RFID), Wi-Fi connection location, or device Global Positioning System (GPS) and GSM/CDMA cell IDs. The location is returned with a given accuracy depending on the best location information source available.
- 4Implementation
Deployment in web browsers[edit]
Web pages can use the Geolocation API directly if the web browser implements it. Historically, some browsers could gain support via the Google Gearsplugin, but this was discontinued in 2010 and the server-side API it depended on stopped responding in 2012.[2][3]
The Geolocation API is ideally suited to web applications for mobile devices such as personal digital assistants (PDA) and smartphones. On desktop computers, the W3C Geolocation API works in Firefox since version 3.5, Google Chrome,[4]Opera 10.6,[5]Internet Explorer 9.0,[6] and Safari 5. On mobile devices, it works on Android (firmware 2.0+), iOS, Windows Phone and Maemo. The W3C Geolocation API is also supported by Opera Mobile 10.1 — available for Android and Symbian devices (S60 generations 3 & 5) since November 24, 2010.[7]
Google Gears provided geolocation support for older and non-compliant browsers, including Internet Explorer 7.0+ as a Gears plugin, and Google Chrome which implemented Gears natively. It also supported geolocation on mobile devices as a plugin for the Android browser (pre version 2.0) and Opera Mobile for Windows Mobile. However, the Google Gears Geolocation API is incompatible with the W3C Geolocation API and is no longer supported.
Features[edit]
The result of W3C Geolocation API will usually give 4 location properties, including latitude and longitude (coordinates), altitude (height), and [accuracy of the position gathered], which all depend on the location sources. In some queries, altitude may yield or return no value.
Location sources[edit]
The Geolocation API does not provide the location information. The location information is obtained by a device (such as a smartphone, PC or modem), which is then served by the API to be brought in browser. Usually geolocation will try to determine a device's position using one of these several methods.
- GPS (Global Positioning System)
- This happens for any device which has GPS capabilities. A smartphone with GPS capabilities and set to high accuracy mode will be likely to obtain the location data from this. GPS calculate location information from the satellite signal. It has the highest accuracy; in most Android smartphones, the accuracy can be up to 10 metres.
- Mobile Network Location
- Mobile phone tracking is used if a cellphone or wireless modem is used without a GPS chip built in.
- WiFi Positioning System
- If WiFi is used indoors, a Wi-Fi positioning system is the likeliest source. Some WiFi spots have location services capabilities.
- IP Address Location
- Location is detected based on nearest Public IP Address on a device (which can be a computer, the router it is connected to, or the ISP the router uses). The location depends on the IP information available, but in many cases where the IP is hidden behind Internet Service Provider NAT, the accuracy is only to the level of a city, region or even country.
Implementation[edit]
Though the implementation is not specified, W3C Geolocation API is built on extant technologies, and is heavily influenced by Google Gears Geolocation API. Download spss 16 full crack. Example: Firefox's Geolocation implementation[8] uses Google's network location provider.[9]
Google Gears Geolocation works by sending a set of parameters that could give a hint as to where the user's physical location is to a network location provider server, which is by default the one provided by Google (code.l.google.com).[10] Some of the parameters are lists of sensed mobile cell towers and Wi-Fi networks, all with sensed signal strengths. These parameters are encapsulated into a JavaScript Object Notation (JSON) message and sent to the network location provider via HTTP POST. Based on these parameters, the network location provider can calculate the location. Common uses for this location information include enforcing access controls, localizing and customizing content, analyzing traffic, contextual advertising and preventing identity theft.[11] Laurel and hardy yts.
Example code[edit]
Simple JavaScript code that checks if the browser has the Geolocation API implemented and then uses it to get the current position of the device. this code creates a function which can be called on HTML using <body onload='geoFindMe()'>
:
See also[edit]
References[edit]
- ^Popescu, Andrei (editor, Google Inc.). 'Geolocation API Specification: W3C Recommendation 24 October 2013'. W3C. Retrieved 4 February 2016.
- ^'Geolocation API: Gears API: Google Code'. 9 July 2009.
- ^GeolocationAPI - gears - Provides the geolocation of a device running a Gears-enabled web browser. - Improving Your Web Browser - Google Project Hosting. Code.google.com. Retrieved on 2014-06-01.
- ^'A new Chrome stable release: Welcome, Mac and Linux!'. 25 May 2010.
- ^Kleinhout, Huib (1 July 2010). 'Opera 10.60 goes final'. My Opera. Opera Software. Retrieved 2 July 2010.
- ^'W3C Geolocation API in IE9'.
- ^Opera.com (25 November 2010). 'Opera Mobile 10.1 for Nokia smartphones goes final'.
- ^'Location-Aware Browsing'. Mozilla Firefox. Mozilla.
- ^'Geolocation API Network Protocol: Gears API'. Google Code. Google. Retrieved 8 August 2011.
- ^'WebScanNotes.com: W3C Geolocation API'. WebScanNotes.com.
- ^King, Kevin F. (8 June 2010). 'Personal Jurisdiction, Internet Commerce, and Privacy: The Pervasive Legal Consequences of Modern Geolocation Technologies'. SSRN1622411.Missing or empty
url=
(help)