I created a Maps API key and my Buildsettings looks like:
settings =
{
orientation =
{
default ="portrait",
supported = {"portrait"},
},
android =
{
usesPermissions =
{
"android.permission.INTERNET",
--optional permission used to display current location via the GPS
"android.permission.ACCESS_FINE_LOCATION",
--optional permission used to display current location via WiFi or cellular service
"android.permission.ACCESS_COARSE_LOCATION",
},
usesFeatures =
{
-- If you set permissions "ACCESS_FINE_LOCATION" and "ACCESS_COARSE_LOCATION" above,
-- you may want to set up your app to not require location services as follows.
-- Otherwise, devices that do not have location sevices (such as a GPS) will be unable
-- to purchase this app in the app store.
{ name = "android.hardware.location", required = false },
{ name = "android.hardware.location.gps", required = false },
{ name = "android.hardware.location.network", required = false }
},
},
iphone =
{
plist =
{
NSLocationAlwaysUsageDescription = "This app would like to use location services.",
NSLocationWhenInUseUsageDescription = "This app would like to use location services.",
},
},
}
My config.lua looks like:
application =
{
content =
{
},
license =
{
google =
{
mapsKey = "XXXXXXXXXXXXXXXXXXXXX",
},
},
}
Finally I create the mapview in a scene whose code looks like this:
--- These 2 lines should appear in every composer scene
local composer = require( "composer" )
local scene = composer.newScene()
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
scene.create = function(self,event)
-- Create a native map view
end
scene.show = function(self,event)
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
local myMap = native.newMapView(display.contentCenterX,display.contentCenterY, display.contentWidth-300, display.contentHeight-300 )
-- Display map as vector drawings of streets (other options are "satellite" and "hybrid")
myMap.mapType = "standard"
-- Initialize map to a real location
myMap:setCenter( 37.331692, -122.030456 )
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
end
end
scene.hide = function(self,event)
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is on screen (but is about to go off screen)
print("will hide")
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
print("did hide")
end
end
scene.destroy = function (self, event )
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return scene
On running the build on the phone I see this:
Can’t figure out what is wrong. Any help would be appreciated.