getLocation(params: Object)

Requires:
MapKit≥1.0.6@ray-js/ray≥1.2.10
Platforms:
iOSAndroid
import { map } from '@ray-js/ray';

const { getLocation } = map;

// Promise usage
try {
  const res = await getLocation({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Get current location and speed

Parameters

PropertyTypeRequiredDescription
typestringYeswgs84 returns GPS coordinates; gcj02 returns coordinates usable with openLocation
altitudebooleanYesPassing true returns altitude. Because obtaining altitude requires higher accuracy, it will slow the API response.
isHighAccuracybooleanYesEnable high-accuracy location
highAccuracyExpireTimenumberYesHigh-accuracy location timeout (ms). Returns the highest possible accuracy within the specified time. High-accuracy positioning only takes effect when this value is greater than 3000 ms.
complete() => voidNoCompletion callback (executed on both success and failure)
success(params: Object) => voidNoCallback on successful API call
fail(params: Object) => voidNoFailure callback
success callback parameters
PropertyTypeDescriptionMapKit Since
latitudenumberLatitude, range -90 to 90; negative values indicate southv3.0.5
longitudenumberLongitude, range -180 to 180; negative values indicate westv3.0.5
speednumberSpeed, unit: m/sv3.0.5
accuracynumberLocation accuracyv3.0.5
altitudenumberAltitude, unit: mv3.0.5
verticalAccuracynumberVertical accuracy, in meters (not available on Android, returns 0)v3.0.5
horizontalAccuracynumberHorizontal accuracy, in metersv3.0.5
cityNamestringCity namev3.0.5
streetNamestringStreet namev3.0.5
addressstringLocation name. Historically, iOS returned an Array; use the formatAddress field insteadv3.0.5
formatAddressstringFormatted addressv3.6.0
countryCodestringCountry codev3.1.0
postalCodestringPostal codev3.1.0
countryNamestringCountry namev3.1.1
provincestringProvince namev3.1.1
districtstringDistrict/county name (second-level administrative region)v3.1.1
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

import { map } from '@ray-js/ray'

map.getLocation({
  type: "gcj02",
  altitude: false,
  isHighAccuracy: false,
  highAccuracyExpireTime: 3000,
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});