insert google map into android app

I tried to make an app that can view google map inside it
here’s my code

myMap = native.newMapView( 20, 20, 280, 300 )  
--8.6662, 115.2278 = myMap:getAddressLocation ( "bendega warung" )  
myMap.mapType = "standard"  
myMap: setCenter ( -8.6662, 115.2279 )  
local function callMap()  
 -- Fetch the user's current location  
 local currentLocation = myMap:getUserLocation()  
 if currentLocation then  
 -- Move map so that current location is at the center  
 local currentLatitude = currentLocation.latitude --I've tried to change latitude 9-8.6662) and longitude (115.2279) into number like above, still error  
 local currentLongitude = currentLocation.longitude  
 myMap:setCenter( currentLatitude, currentLongitude, true )  
  
 -- Look up nearest address to this location (this is returned as a "mapAddress" event, handled above)  
 myMap:nearestAddress( currentLatitude, currentLongitude )  
 end  
end  
callMap()  

error message:
attempt to index global ‘myMap’ (a nil value) [import]uid: 197096 topic_id: 34984 reply_id: 334984[/import]

I noticed two issues in your code. Line 4, there is an extra " " after myMap: in the statement:

 myMap: setCenter ( -8.6662, 115.2279 ) -- remove the space after myMap:  

The last line of your code is different than the corona example code, which reads:

 timer.performWithDelay( 1000, callMap)  

When I made these two changes to your code, it worked for me. [import]uid: 79933 topic_id: 34984 reply_id: 139127[/import]

thanks for your reply
it work
now, can I integrated my app to google map?? is it possible?
or can I add ‘get direction’ feature to my app? any tutorial for it?
sorry for asking so many questions
[import]uid: 197096 topic_id: 34984 reply_id: 139251[/import]

I noticed two issues in your code. Line 4, there is an extra " " after myMap: in the statement:

 myMap: setCenter ( -8.6662, 115.2279 ) -- remove the space after myMap:  

The last line of your code is different than the corona example code, which reads:

 timer.performWithDelay( 1000, callMap)  

When I made these two changes to your code, it worked for me. [import]uid: 79933 topic_id: 34984 reply_id: 139127[/import]

thanks for your reply
it work
now, can I integrated my app to google map?? is it possible?
or can I add ‘get direction’ feature to my app? any tutorial for it?
sorry for asking so many questions
[import]uid: 197096 topic_id: 34984 reply_id: 139251[/import]

I’ve another question
I cannot insert my map into local group, it made another object overlap my map
and it cannot join into transition effect from director class, so my map showed suddenly while the background and another object transitioning [import]uid: 197096 topic_id: 34984 reply_id: 141290[/import]

I’ve another question
I cannot insert my map into local group, it made another object overlap my map
and it cannot join into transition effect from director class, so my map showed suddenly while the background and another object transitioning [import]uid: 197096 topic_id: 34984 reply_id: 141290[/import]

local currentLocation

local currentLatitude

local currentLongitude

local locationText

local alert

local myMap

myMap=native.newMapView( 0, 0, 160, 240 )

myMap.mapType = “standard” --myMap.mapType = “normal”

myMap.x = display.contentWidth / 2

myMap.y = 120

myMap:setCenter( 37.331692, -122.030456 )

function callMap()

   currentLocation = myMap:getUserLocation()

    if currentLocation then

       print(currentLocation…“current location is”)

       currentLatitude = currentLocation.latitude

       currentLongitude = currentLocation.longitude

        myMap:setCenter( currentLatitude, currentLongitude, true )

        myMap:nearestAddress( currentLatitude, currentLongitude )

    end

end

timer.performWithDelay( 1000, callMap)

i am getting the error like attempt to index local myMap a nil value

Hi @nirosha.p59,

Can you specify which device you’re testing this on?

Thanks,

Brent

local currentLocation

local currentLatitude

local currentLongitude

local locationText

local alert

local myMap

myMap=native.newMapView( 0, 0, 160, 240 )

myMap.mapType = “standard” --myMap.mapType = “normal”

myMap.x = display.contentWidth / 2

myMap.y = 120

myMap:setCenter( 37.331692, -122.030456 )

function callMap()

   currentLocation = myMap:getUserLocation()

    if currentLocation then

       print(currentLocation…“current location is”)

       currentLatitude = currentLocation.latitude

       currentLongitude = currentLocation.longitude

        myMap:setCenter( currentLatitude, currentLongitude, true )

        myMap:nearestAddress( currentLatitude, currentLongitude )

    end

end

timer.performWithDelay( 1000, callMap)

i am getting the error like attempt to index local myMap a nil value

Hi @nirosha.p59,

Can you specify which device you’re testing this on?

Thanks,

Brent

this code gives me an error message "attempt to index global ‘myMap’ (a nil value) "

how can i fixed it. .could anyone help me. . Tnx :slight_smile:

[lua] myMap = native.newMapView( 20, 20, 280, 300 )

myMap.mapType =“standard”

– Initialize map to a real location, since default location (0,0) is not very interesting

myMap:setCenter( 7.293001, 125.393143 )

local function callMap()

    – Fetch the user’s current location

    – Note: in XCode Simulator, the current location defaults to Apple headquarters in Cupertino, CA

    local currentLocation = myMap:getUserLocation()

    if currentLocation then

        – Move map so that current location is at the center

        local currentLatitude = currentLocation.latitude

        local currentLongitude = currentLocation.longitude

        myMap:setCenter( currentLatitude, currentLongitude, true )

        – Look up nearest address to this location (this is returned as a “mapAddress” event, handled above)

        myMap:nearestAddress( currentLatitude, currentLongitude )

    end

end

– A function to handle the “mapAddress” event (also known as “reverse geocoding”)

local mapAddressHandler = function( event )

    local locationText =

        "Latitude: " … currentLatitude … 

        ", Longitude: " … currentLongitude …

        ", Address: " … event.streetDetail … " " … event.street …

        ", " … event.city …

        ", " … event.region …

        ", " … event.country …

        ", " … event.postalCode

    local alert = native.showAlert( “You Are Here”, locationText, { “OK” } )

end

– A listener for the address lookup result

– (This could also be a table listener on the map itself, in case you have more than one simultaneous map.)

Runtime:addEventListener( “mapAddress”, mapAddressHandler )

timer.performWithDelay( 1000, callMap )         – get current location after 1 second [/lua]

Hi @nojlamoliva,

Where in the code is the error occurring? I realize the line numbers reflected here (in the forum post) won’t mimic your actual code, so if you can just show the actual line which is choking, we can inspect and go from there.

Thanks,

Brent

tnx for immediate reply sir, this is the error of my code! 

this code gives me an error message "attempt to index global ‘myMap’ (a nil value) "

how can i fixed it. .could anyone help me. . Tnx :slight_smile:

[lua] myMap = native.newMapView( 20, 20, 280, 300 )

myMap.mapType =“standard”

– Initialize map to a real location, since default location (0,0) is not very interesting

myMap:setCenter( 7.293001, 125.393143 )

local function callMap()

    – Fetch the user’s current location

    – Note: in XCode Simulator, the current location defaults to Apple headquarters in Cupertino, CA

    local currentLocation = myMap:getUserLocation()

    if currentLocation then

        – Move map so that current location is at the center

        local currentLatitude = currentLocation.latitude

        local currentLongitude = currentLocation.longitude

        myMap:setCenter( currentLatitude, currentLongitude, true )

        – Look up nearest address to this location (this is returned as a “mapAddress” event, handled above)

        myMap:nearestAddress( currentLatitude, currentLongitude )

    end

end

– A function to handle the “mapAddress” event (also known as “reverse geocoding”)

local mapAddressHandler = function( event )

    local locationText =

        "Latitude: " … currentLatitude … 

        ", Longitude: " … currentLongitude …

        ", Address: " … event.streetDetail … " " … event.street …

        ", " … event.city …

        ", " … event.region …

        ", " … event.country …

        ", " … event.postalCode

    local alert = native.showAlert( “You Are Here”, locationText, { “OK” } )

end

– A listener for the address lookup result

– (This could also be a table listener on the map itself, in case you have more than one simultaneous map.)

Runtime:addEventListener( “mapAddress”, mapAddressHandler )

timer.performWithDelay( 1000, callMap )         – get current location after 1 second [/lua]

Hi @nojlamoliva,

Where in the code is the error occurring? I realize the line numbers reflected here (in the forum post) won’t mimic your actual code, so if you can just show the actual line which is choking, we can inspect and go from there.

Thanks,

Brent

tnx for immediate reply sir, this is the error of my code!