I am testing the new Mapview for Android and have ran into some difficulty. The following code displays the map and the user’s current location correctly on IOS devices. The print statements verify that the correct lat/long is being used. However, if I run this same code on an Android device, the map displays with the user’s current location correctly but the print statements show lat/lnog as “nil” and I get a Lua runtime error that says “Function mapView:setCenter() was given an invalid ‘latitude’ argument. Was expecting a number.” Which I assume is because lat/long is nil. The permissions in the build.settings are correct with the ACCESS_FINE_LOCATION entry. Any ideas on why this runs correctly on IOS but not Android? All ideas are greatly appreciated!
Thanks,
Scott
[code]
– Load external Lua libraries
local ui = require( “ui” )
– define variables
local currentLocation, currentLatitude, currentLongitude
– create map
myMap = native.newMapView( 20, 20, 300, 220 )
myMap.mapType = “standard”
myMap.x = display.contentWidth / 2
myMap.y = 120
– get user’s current location
local function callMap()
currentLocation = myMap:getUserLocation()
currentLatitude = currentLocation.latitude
currentLongitude = currentLocation.longitude
print ("currentLatitude = ", currentLatitude)
print ("currentLongitude = ", currentLongitude)
– Move map so that current location is at the center
myMap:setCenter( currentLatitude, currentLongitude, true )
end
timer.performWithDelay(1000, callMap)
[/code] [import]uid: 85963 topic_id: 31115 reply_id: 331115[/import]
