Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

City and State from GPS
Started by atanas Dec 23 2013 04:00 AM

13 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Contributor

  • 225 posts
  • Corona SDK

Hi,

Anyone knows how to retrieve the current city and state from the GPS coordinates?

Thanks

[TOPIC: post.html]
#2

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

I haven't done this but here's how I think I could make it work.

 

Google "Reverse geocoding" and you will come across a number of scripts / services that return a street address when supplied with a GPS coord. 

 

I would then put that in a simple php script (host it on my server) that receives a GPS coord from a caller (my mobile app), does the reverse geocoding php calls and return a json response to the caller.

 

Sounds like a neat challenge. Let me see if I can crack this one.



[TOPIC: post.html]
#3

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

See https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding

 

You could simply call 

 

http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true_or_false

 

And get a long JSON response on the calling mobile app and then go from there as well. 

 

I like the php intermediary idea but it is not absolutely needed. 



[TOPIC: post.html]
#4

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Contributor

  • 225 posts
  • Corona SDK

Thanks Kerem,

 

That would help a lot to make it easier for users.

 

Isn't the google geocoding limited on the number of requests though?

 

Thanks

  Atanas



[TOPIC: post.html]
#5

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

Usage limits say you get 2500 lookups per 24 hours. If your mobile app is making the lookups directly then I think each mobile device running the app will count as one user so its really hard to consume all 2500 calls per day. If you go the php on server route you could hit the limit sooner or later so perhaps mobile calling Google api is better way in this case. 



[TOPIC: post.html]
#6

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Contributor

  • 225 posts
  • Corona SDK

2500 isn't as bad as I thought, but wasn't the limit per appkey? 

 

I seem to remember there were some free reverse geocoding sites as well?

 

Thanks,

  Atanas



[TOPIC: post.html]
#7

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

A call like this : http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true

 

gives me a response without requiring me to supply an appkey or any other identifier so I'm guessing they track the requests coming from IP addresses or other identifiers. This is why I'm hopeful each instance of your mobile app running on a device will be entitled 2500 calls max per day.

 

I see a number of other alternatives listed here : 

 

http://stackoverflow.com/questions/3392160/converting-latitude-longitude-into-city-name-reverse-geolocating

 

Since you don't need full address matching any of these should do. If you needed full address you would obviously want the service with best data which is quite likely Google. 



[TOPIC: post.html]
#8

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Contributor

  • 225 posts
  • Corona SDK

Thanks a lot Kerem, will look them up



[TOPIC: post.html]
#9

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

You are most welcome.

 

Also take a look at the MapView sample from CL (its in Samples/Interface folder). Current Location button uses the Map API to display the map of your current location but also returns address info. I believe this one relies on Apple data and it does not seem to be limited. Not sure if you can make use of this without showing the map etc but I suspect you could. Could be another option. 



[TOPIC: post.html]
#10

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,376 posts
  • Enterprise

Shouldn't this work for you?  http://docs.coronalabs.com/api/type/Map/nearestAddress.html

 

If you don't want to show the map, draw it off screen.

 

Rob



[TOPIC: post.html]
#11

atanas

[GLOBAL: userInfoPane.html]
atanas
  • Contributor

  • 225 posts
  • Corona SDK

Thanks, I will try out how the performance is with loading the map offscreen. 

 

Any way to retrieve the state too?

 

Thanks,

  Atanas



[TOPIC: post.html]
#12

ksan

[GLOBAL: userInfoPane.html]
ksan
  • Corona Geek

  • 2,795 posts
  • Corona SDK

[TOPIC: post.html]
#13

epa

[GLOBAL: userInfoPane.html]
epa
  • Observer

  • 1 posts
  • Corona SDK

Shouldn't this work for you?  http://docs.coronalabs.com/api/type/Map/nearestAddress.html

 

If you don't want to show the map, draw it off screen.

 

Rob

 Hey Rob,

 

I came to this post after searching on google about this feature, but I get a problem when i draw the map off screen.
While the map is inside the screen, i can get the event.city parameter. When i move it outside the screen, it always returns nothing. Any ideas why this is happening?



[TOPIC: post.html]
#14

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,376 posts
  • Enterprise

I'm not sure, but instead of pushing it off screen, what happens if you set it's .isVisible property to false (or .alpha = 0)?

 

Rob




[topic_controls]
[/topic_controls]