当前位置:网站首页>JS get the current time, month, day, year, and the uniapp location applet opens the map to select the location

JS get the current time, month, day, year, and the uniapp location applet opens the map to select the location

2022-07-07 14:15:00 Code s Beethoven's note

var datetime = new Date();
var year = datetime.getFullYear();
var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();

this.kaishiriqi = year + "-" + month + "-" + date;

 
 Output      2022-07-06

uni.getLocation(OBJECT)

Get current geographic location 、 Speed .

OBJECT Parameter description

Parameter name type Required explain Platform difference description
typeString no The default is wgs84 return gps coordinate ,gcj02 Return to the coordinates of the State Bureau of Surveying and mapping , Can be used for  uni.openLocation  and map Component coordinates ,App and H5 Positioning needs to be configured SDK Information can support gcj02.
altitudeBoolean no Pass in true Will return altitude information , Because of the high accuracy required to obtain the height , Will slow down the interface return speed Bytedance applet 、 Flying Book applet 、 Alipay applet does not support
geocodeBoolean no Default false, Whether to resolve address information only App Platform support ( Andrew needs to specify type by gcj02 And configure three-way positioning SDK)
highAccuracyExpireTimeNumber no High precision positioning timeout (ms), Returns the highest precision within the specified time , This value 3000ms The above high-precision positioning is effective App (3.2.11+)、H5 (3.2.11+)、 Wechat applet ( Base library 2.9.0+)
timeoutString no The default is 5, Positioning timeout , Unit second Only flybook applet support
cacheTimeoutNumber no Locate cache timeout , Unit second ; Cache the current location data for each location , And make a time stamp , When the next call is in cacheTimeout Endochronic , Return cached data Only fly Book applet 、 Alipay applet support
accuracyString no The default is high, Specify the desired precision , Support high,best. When specifying high when , The expected accuracy value is 100m, When specifying best The expected precision value is 20m. When the accuracy obtained by positioning does not meet the conditions , stay timeout We will continue to locate before , Try to get the positioning results that meet the requirements Only flybook applet support
isHighAccuracyBoolean no Turn on high-precision positioning App (3.4.0+)、H5 (3.4.0+)、 Wechat applet ( Base library 2.9.0+)
successFunction yes Interface calls the successful callback function , Please refer to the return parameter description for the return content .
failFunction no Interface call failed callback function
completeFunction no The callback function at the end of the interface call ( Successful call 、 Failure will be carried out )

success Return parameter description

Parameters explain
latitude latitude , Floating point numbers , The scope is -90~90, A negative number means south latitude
longitude longitude , Floating point numbers , The scope is -180~180, A negative number means the west longitude
speed Speed , Floating point numbers , Company m/s
accuracy The accuracy of the position
altitude Height , Company m
verticalAccuracy Vertical accuracy , Company m(Android Can't get , return 0)
horizontalAccuracy Horizontal accuracy , Company m
address Address information ( only App Client support , Need to configure geocode by true)

address Address information description

attribute type describe explain
countryString Country Such as “ China ”, If this information cannot be obtained, return undefined
provinceString Name of province Such as “ The Beijing municipal ”, If this information cannot be obtained, return undefined
cityString The city name Such as “ The Beijing municipal ”, If this information cannot be obtained, return undefined
districtString District ( county ) name Such as “ Chaoyang District ”, If this information cannot be obtained, return undefined
streetString Street information Such as “ Jiuxianqiao Road ”, If this information cannot be obtained, return undefined
streetNumString Get street number information Such as “3 Number ”, If this information cannot be obtained, return undefined
poiNameStringPOI Information Such as “ Electronic City . International Electronics headquarters ”, If this information cannot be obtained, return undefined
postalCodeString Postal Code Such as “100016”, If this information cannot be obtained, return undefined
cityCodeString City Code Such as “010”, If this information cannot be obtained, return undefined

Example

uni.chooseLocation(OBJECT)

Open map to select location .

Platform difference description

AppH5 Wechat applet Alipay applet Baidu applet Bytedance applet 、 Flying Book applet QQ Applet Kwai Mini program Jingdong applet
xx

OBJECT Parameter description

Parameter name type Required explain Platform difference description
latitudeNumber no Latitude of destination Wechat applet (2.9.0+)、H5-Vue3(3.2.10+)
longitudeNumber no The longitude of the target Wechat applet (2.9.0+)、H5-Vue3(3.2.10+)
keywordString no Search for keywords , only App Platform support
successFunction yes Interface calls the successful callback function , Please refer to the return parameter description for the return content .
failFunction no Interface call failed callback function ( Failed to get location 、 Trigger when the user cancels )
completeFunction no The callback function at the end of the interface call ( Successful call 、 Failure will be carried out )

Be careful

  • Due to platform differences , If SDK Configure Baidu map , Need to set up keyword, To display the relevant location
  • nvue  Support Gaode map and Google Map (3.4+), Baidu maps are not supported
  • HBuilderX 2.4.0+  Not weex Compilation mode only supports Gaode map

success Return parameter description

Parameters explain
name Location name
address Detailed address
latitude latitude , Floating point numbers , The scope is -90~90, A negative number means south latitude , Use gcj02 National Survey Bureau coordinate system .
longitude longitude , Floating point numbers , The scope is -180~180, A negative number means the west longitude , Use gcj02 National Survey Bureau coordinate system .

Example

 

原网站

版权声明
本文为[Code s Beethoven's note]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071202060426.html