Type Function Object Map Library native.* Return value none Revision 2017.3060 Keywords requestLocation See also mapLocation
This is a replacement for the deprecated object:getAddressLocation().
Returns the numerical latitude and longitude values of the given location string. The coordinates are returned as a mapLocation event. The coordinates can then be used to place a marker on the map,
This function will accept virtually any address or intersection format as input, along with the names of some famous landmarks.
object:requestLocation( location, resultHandler )
String. The address, intersection, or landmark.
Listener. The listener function to be invoked for the mapLocation 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( "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 )