Type Function Object Map Library native.* Return value none Revision 2017.3060 Keywords nearestAddress See also mapAddress
Returns the nearest address based on the given latitude and longitude values, returned as a mapAddress event.
object:nearestAddress( latitude, longitude, resultHandler )
Number. The latitude in degrees of the desired location.
Number. The longitude in degrees of the desired location.
Listener. The listener function to be invoked for the mapAddress event.
On Android, you must add the INTERNET
permission to the build.settings
file.
settings = { android = { usesPermissions = { "android.permission.INTERNET", }, }, }
Starting with iOS 8, you must add the NSLocationWhenInUseUsageDescription
key to the plist section of the build.settings
file which contains the reason why you need access to location services.
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 )