Will this work? Determining location of where you are?

UGH!  My apologies, the copy/paste looks terrible even though I am using the lua tags.  Is there a way to fix that?  Hope you all can read it.  SORRY!

I told my programmer that the game cannot (maybe) be played in certain states - I gave him a list and told him to make sure it won’t work there.

He provided the following code.

[lua]

local M = {}

local function getCityTbl( userCity )
    cityTbl = {“Arizona”, “Arkansas”, “Connecticut”, “Delaware”,
     “Florida”, “Illinois”, “Iowa”, “Louisiana”, “Maine”, “Maryland”,
     “North Dakota”, “Tennessee”, “Vermont”, “Puerto Rico”, “Colorado”,
     “Minnesota”, “Indiana”, “Montana”, “South Carolina”}

    for i = 1,#cityTbl do
         if (cityTbl[i] == userCity) then
            return true
        end
    end

    return false
end

M.getCityTbl = getCityTbl
return M

[/lua]

and

[lua]

local function onClickSubmit( event )
    local phase = event.phase
    if (event.phase == “ended”) then
        if (radioButton[1].isOn == true) then
            composer.gotoScene(“SoundSelection”)

        elseif(radioButton[2].isOn == true) then
            
            local loadData = {}
            loadData = loadSave.loadTable(“userlocation.json”)
            if (loadData ~= nil) then
                local cityFlag = cityTbl.getCityTbl( tostring(loadData.city) )
                if (cityFlag) then
                    local alert = native.showAlert( “Alert”, “Your city can’t play competition”, { “OK” } )
                else
                    composer.gotoScene(“tournamentMenu”)
                end
            else
                composer.gotoScene(“tournamentMenu”)
            end
          
                
        elseif(radioButton[3].isOn == true) then
            
            composer.gotoScene(“HowToPlay”)
        
        end
        
    end
end

[/lua]

I also took a look inside the Main file and saw this…

[lua]

– A function to handle the “mapAddress” event (also known as “reverse geocoding”, ie: coordinates -> string).
    local mapAddressHandler = function( event )
        if event.isError then
            – Failed to receive location information.
            print(“errorcode”)
        else
            – Location information received. Display it.
            local locationText =
                    "Latitude: " … currentLatitude …
                    ", Longitude: " … currentLongitude …
                    ", Address: " … ( event.streetDetail or “” ) …
                    " " … ( event.street or “” ) …
                    ", " … ( event.city or “” ) …
                    ", " … ( event.region or “” ) …
                    ", " … ( event.country or “” ) …
                    ", " … ( event.postalCode or “” )
            – local alert = native.showAlert( “Alert”,event.city , { “OK” } )        
            userLocationTbl.city = event.region
            userLocationTbl.country = event.country
            loadSave.saveTable(userLocationTbl,“userlocation.json”)        
            
        end
    end

[/lua]

It just doesn’t look like GPS gets state.  Am I right?  Is there a method to get it?  or do I need to do the simple way I suggested, just post the GPS coordinates (latitude and longitude) and let other users decide if it is in illegal state or not?

Thanks for your help!

I told him these are states/provices not cities.  He said it works.  I have a hard time believing him.

I told him, one easy way is to just get the GEO Location (Lat/Long) and put those on website and if they played from in the state then another user could flag it as illegal.

But, he insists this works.

Can anyone verify?  Sorry, I do not live in the states and have no easy way to see if it really works or not.

Thanks!

You get GPS readings by registering a location listener, see https://docs.coronalabs.com/api/event/location/index.html and the examples on the subpages. Your code is difficult to read, but I don’t see a location listener being registered anywhere, so it doesn’t seem like you have copied the relevant sections.

Are you using geolocation to restrict your users from accessing your app from certain places? What if the user disables their GPS, or can’t access it due to being indoors?

Yes, we check.  If disabled then can’t play.

I didn’t copy all code.  I am only asking if geolocation can determine state/province?  That is most important.  Can it determine if you live in a certain state/province?

Thanks!

Geolocation can determine the things listed on the page I linked you to.

event.accuracy

event.altitude

event.direction

event.errorCode

event.errorMessage

event.latitude

event.longitude

event.name

event.speed

event.time

It is possible to use the coordinates (longitude / latitude) to determine the country, state, and even address, but not on your own; you need to use a reverse geocoding service. Try googling reverse geocoding service.

As _memo says, for your purposes all you’ll get (assuming your code is implemented properly) is a lat/long pair. You have to figure out how to translate those into cities/states/etc. and match against your blacklist.

Also note that there will be edge cases where the user is in one state near the border but the lat/long his device returns will incorrectly indicate he’s in another, through no fault of the user.

You get GPS readings by registering a location listener, see https://docs.coronalabs.com/api/event/location/index.html and the examples on the subpages. Your code is difficult to read, but I don’t see a location listener being registered anywhere, so it doesn’t seem like you have copied the relevant sections.

Are you using geolocation to restrict your users from accessing your app from certain places? What if the user disables their GPS, or can’t access it due to being indoors?

Yes, we check.  If disabled then can’t play.

I didn’t copy all code.  I am only asking if geolocation can determine state/province?  That is most important.  Can it determine if you live in a certain state/province?

Thanks!

Geolocation can determine the things listed on the page I linked you to.

event.accuracy

event.altitude

event.direction

event.errorCode

event.errorMessage

event.latitude

event.longitude

event.name

event.speed

event.time

It is possible to use the coordinates (longitude / latitude) to determine the country, state, and even address, but not on your own; you need to use a reverse geocoding service. Try googling reverse geocoding service.

As _memo says, for your purposes all you’ll get (assuming your code is implemented properly) is a lat/long pair. You have to figure out how to translate those into cities/states/etc. and match against your blacklist.

Also note that there will be edge cases where the user is in one state near the border but the lat/long his device returns will incorrectly indicate he’s in another, through no fault of the user.