How does WeChat Mini Programs get the parameter return returned by the callback function successfully called by the API?

I want to write a public function that gets the location of the user. I currently write that the data of return is not assigned a value because of asynchronous requests, so printing locationData should be undefined. Would like to ask the gods how to write to return the data returned in the success?

< hr >

public.js:

var QQMapWX = require("qqmap-wx-jssdk.js"); //
var qqmapsdk = new QQMapWX({ key: "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" });

function getLocation() {
    var data;
    wx.getLocation({
        type: "wgs84",
        success: function (res) {
            let latitude = res.latitude;
            let longitude = res.longitude;
            qqmapsdk.reverseGeocoder({
                location: {
                    latitude: latitude,
                    longitude: longitude
                },
                success: function (res) {
                    data = res.result;
                }
            });
        },
    });
 
    return data;
}

index.js:

var publicJS = require("../utils/public.js");
 
locationSelect: function() {
    var locationData = publicJS.getLocation();
    console.log(locationData);
}

use Promise

function getLocation() {
    return new Promise(function(resolve, reject){
         wx.getLocation({
            type: 'wgs84',
            success: function (res) {
                let latitude = res.latitude;
                let longitude = res.longitude;
                qqmapsdk.reverseGeocoder({
                    location: {
                        latitude: latitude,
                        longitude: longitude
                    },
                    success: function (res) {
                        resolve(res.result);
                    }
                });
            },
        });
    })
   

}

index:js

var publicJS = require('../utils/public.js');
 
locationSelect: function() { 
    publicJS.getLocation().then(function(locationData){
        console.log(locationData);
    })
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3db76-2c3b1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3db76-2c3b1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?