类型 函数 对象 地图 库 native.* 返回值 无 修订 发行版 2024.3703 关键词 requestLocation 另请参见 mapLocation
这是已弃用的替代品 object:getAddressLocation()。
返回给定地址字符串的数字纬度和经度值。坐标作为 mapLocation 事件返回。然后可以使用坐标在地图上放置标记、
此函数将接受几乎任何地址或交叉路口格式作为输入,以及一些著名地标的名称。
object:requestLocation( location, resultHandler )
字符串。 地址、交叉路口或地标。
侦听器。 为 mapLocation 事件调用的侦听器函数。
## 需要特别注意的
在安卓上,必须向 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( "The specified string is at: " .. event.latitude .. "," .. event.longitude ) myMap:setCenter( event.latitude, event.longitude ) end end myMap:requestLocation( "1900 Embarcadero Road, Palo Alto, CA", locationHandler )