Select Location on Map and get GPS coordinates

Hello,

We are a group of students, new to lua, and we would like to get GPS location from a user-selected-location by touching on the Map.

The user selects a location on the map, it adds a marker on the map, and returns the marker location (Latitude, Longitude).

We have no clue how to do it, does anyone have an idea ?

Basically, we would need an equivalent for “GoogleMap.OnMapClickListener” which returns the LatLng point.

Thanks in advance !

Bad news… With corona, there is no way to do what you described. The main issue is that maps don’t return touch events, although there are other issues as well.

I would recommend you read up in the API documention on native.newMapView to see what the sdk has built in for maps: http://docs.coronalabs.com/api/library/native/newMapView.html

The map support allows you to basically:

  • set a maps “view”, the area of earth it displays

  • place markers at specific gps coords onto the map (by passing in gps coords acquired from the device for instance)

  • detect a tap on a marker that has been placed

  • allow the user to scroll and zoom the map

So maps don’t return an event when you touch them (except markers already placed), which means you can’t tell when the user touches a location (and can’t tell pretty much anything they do with the map). In fact, with the current implementation of newMapView, you can’t even tell where the mapView is displaying (you can set the initial gps coords for the view, but if the user scrolls, there’s no way to tell where it is pointing).

So the maps are pretty limited on input (and also limited on getting basic status info like what the current view coords are). On the good news side, they’re pretty easy to implement (see the coronaLabs sample programs), they are cross platform and will display on 1 billion+ devices out there in the marketplace…

Actually, if you have access to the daily builds the maps do have a tap listener.  If you look at this page http://docs.coronalabs.com/daily/api/library/native/newMapView.html and in the sample code there you can see it.

It goes something like this:

myMap = native.newMapView( 20, 20, 300, 220 ) myMap.mapType = "standard" -- 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 ) -- This is returned as a mapLocation event local function mapLocationListener(event) print("map tapped latitude: ", event.latitude) print("map tapped longitude: ", event.longitude) end myMap:addEventListener("mapLocation", mapLocationListener)

Hi,

I tried to run it’s mapTap sample code, but don’t work listener event…

I was confirmed in the iOS simulator.

  1. mapView tap

  2. mapTapListener don’t work…

Up!

Hi,

The issue was with our documentation.  The event name is actually “mapLocation” and not “mapTap”.  Sorry for the confusion.  The docs will be updated shortly.

Bad news… With corona, there is no way to do what you described. The main issue is that maps don’t return touch events, although there are other issues as well.

I would recommend you read up in the API documention on native.newMapView to see what the sdk has built in for maps: http://docs.coronalabs.com/api/library/native/newMapView.html

The map support allows you to basically:

  • set a maps “view”, the area of earth it displays

  • place markers at specific gps coords onto the map (by passing in gps coords acquired from the device for instance)

  • detect a tap on a marker that has been placed

  • allow the user to scroll and zoom the map

So maps don’t return an event when you touch them (except markers already placed), which means you can’t tell when the user touches a location (and can’t tell pretty much anything they do with the map). In fact, with the current implementation of newMapView, you can’t even tell where the mapView is displaying (you can set the initial gps coords for the view, but if the user scrolls, there’s no way to tell where it is pointing).

So the maps are pretty limited on input (and also limited on getting basic status info like what the current view coords are). On the good news side, they’re pretty easy to implement (see the coronaLabs sample programs), they are cross platform and will display on 1 billion+ devices out there in the marketplace…

Actually, if you have access to the daily builds the maps do have a tap listener.  If you look at this page http://docs.coronalabs.com/daily/api/library/native/newMapView.html and in the sample code there you can see it.

It goes something like this:

myMap = native.newMapView( 20, 20, 300, 220 ) myMap.mapType = "standard" -- 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 ) -- This is returned as a mapLocation event local function mapLocationListener(event) print("map tapped latitude: ", event.latitude) print("map tapped longitude: ", event.longitude) end myMap:addEventListener("mapLocation", mapLocationListener)

Hi,

I tried to run it’s mapTap sample code, but don’t work listener event…

I was confirmed in the iOS simulator.

  1. mapView tap

  2. mapTapListener don’t work…

Up!

Hi,

The issue was with our documentation.  The event name is actually “mapLocation” and not “mapTap”.  Sorry for the confusion.  The docs will be updated shortly.