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

  • SEARCH
  • Home
  • 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 6869993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:37:40+00:00 2026-05-27T03:37:40+00:00

I am writing a website using Python / Django, and am currently doing server-side

  • 0

I am writing a website using Python / Django, and am currently doing server-side geocoding through the geopy module. I would like to implement a progressive enhancement of doing the geocoding via Javascript (to make sure I don’t hit Google’s daily limit of geocode requests / user), and then pass the results of the Javascript geocoding to the server for further processing.

What I am currently doing is using javascript and the Google geocoding API to get the (lat, lon) coordinates and add them as hidden inputs into my form. However, I am not sure how to submit this form with the (lat, lon) without running into an infinite loop. I would rather stay away from sending this via Ajax because for this particular page 99.9% of the page needs to be refreshed, and I would like to keep the design as simple as possible, so Ajax would be overkill.

I played around with putting the event.preventDefault() into an if statement testing for existence of the hidden lat/lon variables, but could not get it to work.

Any ideas? Thanks in advance! Vasiliy

$(document).ready(function() {

var g = new GoogleGeocode();  

//bind event handler
$('#address_form').bind('submit', function(event){

    //get address from form
    var address = $('#id_address').val();

    event.preventDefault();

    //get lat/lon
    g.geocode(address, function(data) {  
        if(data != null) {  
            alert(data.longitude + " " + data.latitude);  
            //insert lat and lon into the form
            $('<input type="hidden" id="lat" name="lat" value="' + data.latitude + '"/>').appendTo('form');
            $('<input type="hidden" id="lon" name="lon" value="' + data.longitude + '"/>').appendTo('form');
        } else {  
            alert('ERROR! Unable to geocode address');  
        }
    });  
});
});
  • 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-05-27T03:37:41+00:00Added an answer on May 27, 2026 at 3:37 am

    You should unbind the form submit event handler once you are sure you have to submit the form. Try this

    $(document).ready(function() {
    
    var g = new GoogleGeocode();  
    
    //bind event handler
    $('#address_form').bind('submit', function(event){
    
        //get address from form
        var address = $('#id_address').val();
    
        event.preventDefault();
    
        //get lat/lon
        g.geocode(address, function(data) {  
            if(data != null) {  
                alert(data.longitude + " " + data.latitude);  
                //insert lat and lon into the form
                $('<input type="hidden" id="lat" name="lat" value="' + data.latitude + '"/>').appendTo('form');
                $('<input type="hidden" id="lon" name="lon" value="' + data.longitude + '"/>').appendTo('form');
    
                 $('#address_form').unbind('submit').submit();
    
            } else {  
                alert('ERROR! Unable to geocode address');  
            }
        });  
    });
    

    });

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

Sidebar

Related Questions

I am writing website and i`d like to implement profile managment. Basic thing would
I'm writing multilingual website. I have several files on server like: /index.php /files.php /funny.php
Quick question. I am writing a website and would like to redirect users to
I am writing my website's backend using Flask and Python 2.7, and have run
I am writing a website using Django. I need to push the web site
I'm writing a website using media queries to handle the mobile version. Would it
I am writing the a generic function for my website using jquery which would
I'm writing a website in JSP using Struts and Hibernate. I'm looking for a
I'm writing a website in ASP.NET MVC, using the ASP.NET MVC 1.0 template that
I am writing some code that connects to a website, and using C#, and

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.