类型 函数 对象 Map 库 native.* 返回值 无 修订 版本 2024.3703 关键字 nearestAddress 另请参阅 mapAddress
根据给定的纬度和经度值返回最近的地址,以 mapAddress 事件的形式返回。
object:nearestAddress( latitude, longitude, resultHandler )
Number. 所需位置的纬度,以度为单位。
Number. 所需位置的经度,以度为单位。
Listener. 为 mapAddress 事件调用的侦听器函数。
在 Android 上,你必须向 build.settings
文件添加 INTERNET
权限。
settings = { android = { usesPermissions = { "android.permission.INTERNET", }, }, }
从 iOS 8 开始,你必须向 build.settings
文件的 plist 部分添加 NSLocationWhenInUseUsageDescription
键,其中包含你需要访问定位服务的理由。
settings = { iphone = { plist = { NSLocationWhenInUseUsageDescription = "A description of why the app needs access to location services." }, }, }
-- Create a native map view local myMap = native.newMapView( 20, 20, 280, 360 ) myMap.x = display.contentCenterX myMap.y = display.contentCenterY local function locationHandler( event ) if ( event.isError ) then print( "Map Error: " .. event.errorMessage ) else print( "Nearest location: " .. event.city .. ", " .. event.country ) end end -- Initialize map to a real location myMap:setCenter( 37.331692, -122.030456 ) myMap:nearestAddress( 38.898748, -77.037684, locationHandler )