Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GeoLocation Zip Code

I am using the following code for getting location and city, but can't get it to give me the zip code if the person gives me permission. Please let me know if this is possible to do with this code. All it is doing is populating a text field if given permission to access.

<script type="text/javascript">
  if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
     $("#location").val(position.address.city+", "+position.address.region);
  });
 }

like image 876
pertrai1 Avatar asked May 17 '11 15:05

pertrai1


2 Answers

Try position.address.postalCode

See the following demo i made to see what is supported by your browser/device

https://jsfiddle.net/gaby/Sx5cj/

like image 57
Gabriele Petrioli Avatar answered Nov 12 '22 20:11

Gabriele Petrioli


Looking at the latest HTML5 Geolocation API, i do not see the support for position.address.city, position.address.region or position.address.city yet. So, i'd have to say that is not currently supported.


Update:

Address look up seems to be supported in firefox per @Gaby aka G. Petrioli answer

like image 8
KJYe.Name Avatar answered Nov 12 '22 20:11

KJYe.Name