Hi
I modified the Mapview example to the code shown below, but the program is not getting to the event handler to get the address of my location. Could someone tell me what I am doing wrong please.
Thanks
[code]
–
– Abstract: MapView sample project
– Demonstrates the API for embedded maps and location data (currently iOS-only)
– Version: 1.0
– Sample code is MIT licensed, see http://developer.anscamobile.com/code/license
– Copyright © 2010 ANSCA Inc. All Rights Reserved.
display.setStatusBar( display.HiddenStatusBar )
– Load external Lua libraries (from project directory)
local ui = require( “ui” )
local isAndroid = “Android” == system.getInfo(“platformName”)
if isAndroid then
native.showAlert(“Not supported”, “Maps not yet supported on Android devices.”, {“OK”}, onComplete)
end
local locationNumber = 1 – a counter to display on location labels
local currentLocation, currentLatitude, currentLongitude
local background = display.newImage( “elpasoatnight.png”, true )
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2
–local label = display.newText( “Maps not supported in Corona Simulator.”, 20, 70, native.systemFont, 14 )
–local label2 = display.newText( “(Build for XCode Simulator or iOS device.)”, 20, 95, native.systemFont, 14 )
– Create a native MapView (requires XCode Simulator build or device build)
– You can create multiple maps, if you like…
myMap = native.newMapView( 20, 20, 300, 220 ) – don’t know I need this in order to display buttons
myMap.mapType = “normal” – other mapType options are “satellite” or “hybrid”
– The MapView is just another Corona display object, and can be moved or rotated, etc.
myMap.x = display.contentWidth / 2
myMap.y = 120
– Initialize map to a real location, El Paso, Tx
myMap:setCenter( 31.8470, -106.5892 )
– A function to handle the “mapAddress” event (also known as “reverse geocoding”)
local mapAddressHandler = function( event )
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
– Create buttons and their functions:
local button2Release = function( event )
– not implemented yet
end
local button1Release = function( event )
– Fetch the user’s current location
currentLocation = myMap:getUserLocation()
currentLatitude = currentLocation.latitude
currentLongitude = currentLocation.longitude
print (“current location”,currentLatitude,currentLongitude) – this prints location fine
– Look up nearest address to this location (this is returned as a “mapAddress” event, handled above)
myMap:nearestAddress( currentLatitude, currentLongitude )
local button2 = ui.newButton{
default = “buttonBlueSmall.png”,
over = “buttonBlueSmallOver.png”,
onRelease = button2Release,
text = “Whos here”,
size = 11,
emboss=true
}
button2.x = display.contentWidth / 8; button2.y = 40
end
local button1 = ui.newButton{
default = “buttonBlueSmall.png”,
over = “buttonBlueSmallOver.png”,
onRelease = button1Release,
text = “U R Here/ck in”,
size = 09,
emboss=true
}
button1.x = display.contentWidth / 8 ; button1.y = 40
– A listener for the address lookup result
Runtime:addEventListener( “mapAddress”, mapAddressHandler ) [import]uid: 95689 topic_id: 17773 reply_id: 317773[/import]
[import]uid: 52491 topic_id: 17773 reply_id: 67876[/import]