Hi Carlos. Thanks for the quick reply. All i did was take the examples from corona and build it into my iphone 4 to do a run test so i guess the currentLatitude and currentLongitude are initialized where they should be. Below is the entire code from the example.
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
– This is where the longtitude and latitude is initialized
local currentLocation, currentLatitude, currentLongitude
local background = display.newImage( “bkg_grass.png”, true )
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2
shadow = display.newRect( 7, 7, 306, 226 )
shadow:setFillColor( 0, 0, 0, 120 )
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 )
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, since default location (0,0) is not very interesting
myMap:setCenter( 37.331692, -122.030456 )
– A handler for the native keyboard
local fieldHandler = function( event )
– Hide keyboard when the user clicks “Return” in this field
if ( “submitted” == event.phase ) then
native.setKeyboardFocus( nil )
end
end
– A native text input field (requires XCode Simulator build or device build)
inputField = native.newTextField( 10, 252, 300, 28, fieldHandler )
inputField.font = native.newFont( native.systemFont, 16 )
inputField.text = “Broadway and Columbus, San Francisco” – example of searchable location
inputField:setTextColor( 45, 45, 45 )
– A function to handle the “mapAddress” event (also known as “reverse geocoding”)
local mapAddressHandler = function( event )
– Tried printing out the city but didn’t work
print("event: "…event.city)
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 button1Release = function( event )
– This calls a Google web API to find the location of the submitted string
– Valid strings include addresses, intersections, and landmarks like “Golden Gate Bridge”, “Eiffel Tower” or “Buckingham Palace”
latitude, longitude = myMap:getAddressLocation( inputField.text )
– Move map so this location is at the center
– (The final parameter toggles map animation, which may not be visible if moving a large distance)
myMap:setCenter( latitude, longitude, true )
markerTitle = "Location " … locationNumber
locationNumber = locationNumber + 1
– Add a pin to the map at the new location
myMap:addMarker( latitude, longitude, { title=markerTitle, subtitle=inputField.text } )
end
local button2Release = function( event )
– Fetch the user’s current location
– Note: in XCode Simulator, the current location defaults to Apple headquarters in Cupertino, CA
currentLocation = myMap:getUserLocation()
currentLatitude = currentLocation.latitude
currentLongitude = currentLocation.longitude
– Move map so that current location is at the center
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
local button3Release = function( event )
myMap:removeAllMarkers()
locationNumber = 1 – reset counter for popup labels
end
local button1 = ui.newButton{
default = “buttonGreen.png”,
over = “buttonGreenOver.png”,
onRelease = button1Release,
text = “Find Location”,
emboss = true
}
local button2 = ui.newButton{
default = “buttonOrange.png”,
over = “buttonOrangeOver.png”,
onRelease = button2Release,
text = “Current Location”,
emboss = true
}
local button3 = ui.newButton{
default = “buttonRed.png”,
over = “buttonRedOver.png”,
onRelease = button3Release,
text = “Remove All Markers”,
emboss = true
}
button1.x = display.contentWidth / 2; button1.y = 320
button2.x = display.contentWidth / 2; button2.y = 380
button3.x = display.contentWidth / 2; button3.y = 440
– 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 )
Sorry for pasting this huge chunk of code but you can see that it is the same as the mapview example given. [import]uid: 39846 topic_id: 8548 reply_id: 30749[/import]