Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:01:06+00:00 2026-06-04T20:01:06+00:00

i need to use geolocation in my website for the banner. I found this

  • 0

i need to use geolocation in my website for the banner.
I found this library which seems to be good:

In my page i added this code and the browser shows me the alert to allow to get the position.

Code:

<script type="text/javascript">
    if(geo_position_js.init()){
        geo_position_js.getCurrentPosition(success_callback,error_callback,{enableHighAccuracy:true});
    }
    else{
        alert("Functionality not available");
    }

    function success_callback(p)
    {

        var latitudine = +p.coords.latitude.toFixed(2);
        var longitudine = p.coords.longitude.toFixed(2);

        alert(latitudine+' - '+longitudine);
    }

    function error_callback(p)
    {
        alert('error='+p.message);
    }                       

</script>

I can see the alert without problem but i need to get the city to load different banner.
How can I do that?

I also found this service: findNearbyPlaceName

which allow to find country etc from the latitude and longitude, but how can I use this information? I see that they have a callback with xml or json, i tried to get the url with this code but it is wrong cause browser doesn’t show the alert:

<script type="text/javascript">
    if(geo_position_js.init()){
        geo_position_js.getCurrentPosition(success_callback,error_callback,{enableHighAccuracy:true});
    }
    else{
        alert("Functionality not available");
    }

    function success_callback(p)
    {

        var latitudine = +p.coords.latitude.toFixed(2);
        var longitudine = p.coords.longitude.toFixed(2);

        $.getJSON(
                     'http://http://api.geonames.org/findNearbyPlaceNameJSON?lat='+latitudine+'&lng='+longitudine, 
                        function(data) {
                            alert(data);
                        }
        );

    }

    function error_callback(p)
    {
        alert('error='+p.message);
    }                       

</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:01:07+00:00Added an answer on June 4, 2026 at 8:01 pm

    What you need is a “reverse geocoder”.

    With a reverse geocoder you can get the city name (even the street name) for particular coordinate.

    A very simple way would be to use Google’s Geocoder available in Google Maps API V2 and V3:

      var geocoder;
    
      function codeLatLng(latitude, longitude) {
        var
            geocoder = new google.maps.Geocoder(),
            latlng = new google.maps.LatLng(latitude, longitude);
    
        geocoder.geocode({'latLng': latlng}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            if (results[1]) {
              // results[1].formatted_address contains the city name
            }
          } else {
            alert("Geocoder failed due to: " + status);
          }
        });
      }
    

    Example (Source): https://developers.google.com/maps/documentation/javascript/geocoding#ReverseGeocoding

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need use this code: <%= button_tag :class => btn btn-primary do %> <%=
I need use this method with three distinct classes: Orders, Customers, Suppliers public void
So, I need use this event so I can navigate trought blog posts. I
I need to use javascript to get the itemid of the current page in
I need to use geolocation to Android (using Monodroid). And I'm left with two
I need use a progress bar with the pbstMarquee style, I read this question
I need use web services from a Samsung Smart TV app, but this services
HI guys, There is an abc.jar under /tomcat_lib. I need use this in my
I need use Insert Ignore for my table, which have Unique index on several
I'm writing web application for mobile phones and I need to use geolocation. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.