Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version.

getCurrentPosition method

Obtains the geographic position, in terms of latitude and longitude coordinates, of the device running Windows Internet Explorer.

Geolocation API Specification, Section 5.1Internet Explorer 9



var retval = geolocation.getCurrentPosition(successCallback, errorCallback, options);


successCallback [in]

Type: Object

The handler function to call when geographic position is successfully obtained. The function specified by the successCallback parameter takes one position parameter.

errorCallback [in, optional]

Type: Object

The handler function to call when the attempt to obtain geographic position fails. The function specified by the errorCallback parameter takes one positionError parameter. To use the options parameter without using the errorCallback parameter, set the errorCallback parameter to null.

options [in, optional]

Type: Object

An object literal that uses JSON encoding to specify one or more of the following attributes and the desired value.


Specify true to obtain the most accurate position possible, or false to optimize in favor of performance and power consumption.


An Integer value that indicates the time, in milliseconds, allowed for obtaining the position.

If timeout is Infinity (the default value), the location request will not time out.

If timeout is zero (0) or negative, the results depend on the behavior of the location provider.


An Integer value indicating the maximum age, in milliseconds, of cached position information.

If maximumAge is non-zero, and a cached position that is no older than maximumAge is available, the cached position will be used instead of requiring that getCurrentPositionobtain an updated location.

If maximumAge is zero (0), getCurrentPosition will always try to obtain an updated position, even if a cached position is already available.

If maximumAge is Infinity, any cached position will be used regardless of its age, and getCurrentPosition will only try to obtain an updated position if no cached position data exists.

Return value


If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information


Windows Internet Explorer 9. This property is supported only for webpages displayed in IE9 Standards mode. For more information, see Defining Document Compatibility.

When the getCurrentPosition function is called, it initiates a request to acquire the geographic position, and then returns immediately. If the geographic position is successfully obtained, the callback function defined in the successCallback parameter is called. Te position parameter of that function contains the data describing the current geographic location of the device running Internet Explorer.

If the geographic location cannot be obtained and a callback function is specified as the errorCallback parameter, that function is called. The error parameter of the errorCallback function contains an error code indicating the reason for failure.

Note  The first time a web application calls the getCurrentPosition function, Internet Explorer requests permission to access the geographic location of the browser, unless the user has previously chosen to always allow or always deny permission for the website to determine location. If the user denies permission, the function declared by the errorCallback is called, and the code attribute of the error parameter of that function is set to PositionError.PERMISSION_DENIED.

Support for the attributes of the options parameter depends on the location provider available to the device running Internet Explorer. There is no guarantee that changing the properties of these attributes will affect the results reported by the location provider.


The following example shows how to call the getCurrentPosition function and handle the incoming position data using callback functions. When the user clicks a button, the example listenForPositionUpdates function is called, which checks that the geolocation object is available before it calls the getCurrentPosition function. When the position is obtained, the callback function updates the text boxes in the page by using the latitude and longitude coordinates. If an error occurs while obtaining location, the error callback function displays a message based on the error object's code attribute.

<!DOCTYPE html>  
<title>Location Test with Buttons</title>
<script type="text/javascript">
function setText(val, e) {
    document.getElementById(e).value = val;
function insertText(val, e) {
    document.getElementById(e).value += val;
var nav = null; 
function requestPosition() {
  if (nav == null) {
      nav = window.navigator;
  if (nav != null) {
      var geoloc = nav.geolocation;
      if (geoloc != null) {
          geoloc.getCurrentPosition(successCallback, errorCallback);
      else {
          console.log("Geolocation not supported");
  else {
      console.log("Navigator not found");
function successCallback(position)
   setText(position.coords.latitude, "latitude");
   setText(position.coords.longitude, "longitude");
function errorCallback(error) {
    var message = "";   
    // Check for known errors
    switch (error.code) {
        case error.PERMISSION_DENIED:
            message = "This website does not have permission to use " + 
                      "the Geolocation API";
        case error.POSITION_UNAVAILABLE:
            message = "The current position could not be determined.";
            message = "The current position could not be determined " + 
                      "within the specified timeout period.";            
    // If it's an unknown error, build a message that includes 
    // information that helps identify the situation, so that 
    // the error handler can be updated.
    if (message == "")
        var strErrorCode = error.code.toString();
        message = "The position could not be determined due to " + 
                  "an unknown error (Code: " + strErrorCode + ").";
<label for="latitude">Latitude: </label><input id="latitude" /> <br />
<label for="longitude">Longitude: </label><input id="longitude" /> <br />
<input type="button" onclick="requestPosition()" value="Get Latitude and Longitude"  /> 

See also