tencent cloud

Feedback

Location

Last updated: 2024-03-04 23:05:07

    getLocation

    This method is used via wx.getLocation(Object object).
    Note:
    Prior to invocation, user authorization "scope.userLocation" is required.
    Feature Description: Gets the current geographical location and speed. This interface cannot be invoked once the user exits the mini program.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    type
    string
    wgs84
    No
    WGS84 returns GPS coordinates, while GCJ02 provides coordinates that can be used with wx.openLocation.
    altitude
    string
    false
    No
    Passing in "true" will return altitude information. As acquiring altitude requires high precision, it will slow down the response of the interface.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    latitude
    number
    Latitude, ranging from -90 to 90, with negative values indicating southern latitude.
    longitude
    number
    Longitude, ranging from -180 to 180, with negative values indicating western longitude.
    speed
    number
    Velocity, measured in meters per second (m/s)
    accuracy
    number
    Precision of the location
    altitude
    number
    Height, measured in (m)
    verticalAccuracy
    number
    Vertical accuracy, measured in meters (m). (Cannot be obtained on Android, returning 0)
    horizontalAccuracy
    number
    Horizontal accuracy, measured in meters (m)
    Sample Code
    wx.getLocation({
    type: 'gcj02',
    success (res) {
    const latitude = res.latitude
    const longitude = res.longitude
    const speed = res.speed
    const accuracy = res.accuracy
    }
    })
    Note:
    The location simulation in the tool uses IP positioning, which may introduce some degree of error. Currently, the tool only supports gcj02 coordinates.
    When using third-party services for reverse address resolution, make sure the default coordinate system of the third-party service is confirmed for accurate coordinate conversion.

    choosePoi

    This API is used via wx.choosePoi(Object object).
    Feature Description: Opens the POI list to select a location, which supports both vague positioning (accurate to the city) and precise positioning in a mixed selection.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    type
    number
    When selecting a city, the value is 1; when selecting an exact location, the value is 2.
    city
    number
    City Name
    name
    string
    Location Name
    address
    string
    Exact Address
    latitude
    number
    Latitude, a floating-point number, ranging from -90 to 90, where a negative number indicates southern latitude, using the gcj02 National Administration of Surveying, Mapping and Geoinformation coordinate system (to be deprecated).
    longitude
    number
    Longitude, a floating-point number, ranging from -180 to 180, where a negative number indicates western longitude, using the gcj02 National Administration of Surveying, Mapping and Geoinformation coordinate system (to be deprecated).

    chooseLocation

    This API is used via wx.chooseLocation(Object object).
    Feature Description: Opens the map to select a location.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    type
    string
    tencent
    No
    Tencent Maps (tencent), Google Maps (google), supported by IDE only.
    latitude
    number
    -
    No
    Target location's latitude.
    longitude
    number
    -
    No
    Target location's longitude.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    name
    string
    Location Name
    address
    string
    Exact Address
    latitude
    number
    Latitude, a floating-point number, ranging from -90 to 90, where a negative number indicates southern latitude, using the gcj02 National Administration of Surveying, Mapping and Geoinformation coordinate system.
    longitude
    number
    Longitude, a floating-point number, ranging from -180 to 180, where a negative number indicates western longitude, using the gcj02 National Administration of Surveying, Mapping and Geoinformation coordinate system.

    stopLocationUpdate

    This API is used via wx.stopLocationUpdate(Object object).
    Feature Description: Stops monitoring real-time location changes, halting message reception in both the frontend and backend.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    

    startLocationUpdateBackground

    This API is used via wx.startLocationUpdateBackground(Object object).
    Feature Description: Enables the mini program to receive location messages when entering the frontend and backend, which requires guiding the user to give "authorization". Once authorized, the mini program can receive location message updates during operation or when in the backend.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    type
    string
    gcj02
    No
    WGS84 returns GPS coordinates, while GCJ02 provides coordinates that can be used with wx.openLocation.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

    startLocationUpdate

    This API is used via wx.startLocationUpdate(Object object).
    Feature Description: Enables the mini program to receive location messages upon entering the frontend.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    type
    string
    Coordinates, gcj02
    No
    WGS84 returns GPS coordinates, while GCJ02 provides coordinates that can be used with wx.openLocation.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)

    openLocation

    This API is used via wx.openLocation(Object object).
    Feature Description: Uses the built-in map to view the location.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    type
    string
    tencent
    No
    Tencent Maps (tencent), Google Maps (google), supported by IDE only.
    latitude
    number
    -
    Yes
    Latitude, ranging from -90 to 90, where a negative number indicates southern latitude, using the gcj02 National Administration of Surveying, Mapping and Geoinformation coordinate system.
    longitude
    number
    -
    Yes
    Longitude, ranging from -180 to 180, where a negative number indicates western longitude, using the gcj02 National Administration of Surveying, Mapping and Geoinformation coordinate system.
    scale
    number
    18
    No
    Zoom scale, ranging from 5 to 18.
    name
    string
    -
    No
    Location Name
    address
    string
    -
    No
    Detailed description of the address.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.getLocation({
    type: 'gcj02', // Returns longitude and latitude that can be used for wx.openLocation.
    success (res) {
    const latitude = res.latitude
    const longitude = res.longitude
    wx.openLocation({
    latitude,
    longitude,
    scale: 18
    })
    }
    })

    onLocationChangeError

    This API is used via wx.onLocationChangeError(function listener).
    Feature Description: Cancels monitoring, which is triggered when the continuous location interface returns a failure.
    Parameter and Description: Callback function of "function callback".

    onLocationChange

    This API is used via wx.onLocationChange(function listener).
    Feature Description: Monitors real-time geographical location change events, which needs to be used in conjunction with wx.startLocationUpdateBackground and wx.startLocationUpdate.
    Parameter and Description: Function callback.
    Callback Function Parameters for Real-Time Geographical Location Change Events: Object res.
    Attribute
    Type
    Description
    latitude
    number
    Latitude, ranging from -90 to 90, where a negative number indicates southern latitude, using the gcj02 National Administration of Surveying, Mapping and Geoinformation coordinate system.
    longitude
    number
    Longitude, ranging from -180 to 180, where a negative number indicates western longitude, using the gcj02 National Administration of Surveying, Mapping and Geoinformation coordinate system.
    speed
    number
    Velocity, measured in meters per second (m/s)
    accuracy
    number
    Precision of the location
    altitude
    number
    Height, measured in (m)
    verticalAccuracy
    number
    Vertical accuracy, measured in meters (m). (Cannot be obtained on Android, returning 0)
    horizontalAccuracy
    number
    Horizontal accuracy, measured in meters (m)
    Sample Code
    const _locationChangeFn = function(res) {
    console.log('location change', res)
    }
    wx.onLocationChange(_locationChangeFn)
    wx.offLocationChange(_locationChangeFn)

    offLocationChangeError

    This API is used via wx.offLocationChangeError(function listener).
    Feature Description: Cancels monitoring, which is triggered when the continuous location interface returns a failure.
    Parameter and Description: Callback function of "function callback".

    offLocationChange

    This API is used via wx.offLocationChange(function listener).
    Feature Description: Cancels the monitoring of real-time geographical location change events.
    Parameter and Description: function callback - the callback function for real-time geographical location change events.

    getFuzzyLocation

    This API is used via wx.getFuzzyLocation(Object object).
    Feature Description: Gets the current fuzzy geographical location.
    Parameter and Description: Object.
    Attribute
    Type
    Default value
    Required
    Description
    type
    string
    wgs84
    No
    WGS84 returns GPS coordinates, while GCJ02 provides coordinates that can be used with wx.openLocation.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    latitude
    number
    Latitude, ranging from -90 to 90, with negative values indicating southern latitude.
    longitude
    number
    Longitude, ranging from -180 to 180, with negative values indicating western longitude.
    Sample Code
    wx.getFuzzyLocation({
    type: 'wgs84',
    success (res) {
    const latitude = res.latitude
    const longitude = res.longitude
    }
    })
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support