how to automatically find map addres as customer write in fields - using jquery
See original GitHub issueHi and thank you all for this great package 😃 I am trying to make my signup form more user friendly and i would like user first to write his address etc, and then (i hope) that this widget can find address automaticlly for most users. This is what I have done so far… some jquery that insert the address in the widget autocomplete address field. But it doesnt work the magic. I need the last little bit, please help me 😃
<script type="text/javascript">
$( document ).ready(function() {
$(document).on("click", "#id_street, #id_zipcode, #id_city, #id_country", function(event){
if ($("#id_street").val() && $("#id_zipcode").val() && $("#id_city").val() && $("#id_country").val()){
$("#location-mw-google-address-input").val($("#id_street").val() + ", " + $("#id_zipcode").val() + " " + $("#id_city").val() + ", " + $("#id_country option:selected").text())
}
});
});
</script>
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Place Autocomplete Address Form | Maps JavaScript API
The Place Autocomplete Address Form sample captures selected address components from the Google Places database, and uses them to populate an address form....
Read more >How to make an autocomplete address field with google maps ...
Use script file to load the autocomplete class. Your scripts.js file will look something like this. // scripts.js custom js file $(document).
Read more >jQuery UI and Auto-Complete Address Entry - I Programmer
The autocomplete widget allows you to specify a URL that it will get a JSON or JSONP response. In this case it doesn't...
Read more >Adding an Auto-Complete Address Field to your Forms
This article shows you how to add auto-complete to any form requiring an address. By doing so, you improve the user experience while...
Read more >Let's make a form that puts current location to use in a map!
A potential solution: get the address automatically · Get the HTML button and listen for a click event · Get the user's location...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @michaelhjulskov I have a working solution 😉
To add or delete a marker, you need access to
DjangoGooglePointFieldWidget
instance in your JavaScript. I opened an issue for that #62 I believe author will agree with me or he will give me better approach how to use it.Next thing you need to do is to override template file which renders the map. In my case it was
google-point-field-widget.html
. So go ahead and create a file with the same name in your app in the pathtemplates/mapwidgets/
You can either paste the whole content there or just extend it like I do:
Please notice these 2 changed lines:
I haven’t touched anything else in this file.
map_widget_autofill()
is my own function I have in my JavaScript filescript.js
. I will describe it below.You need to tell Django to load your static file in the
admin.py
:And finally
script.js
:It works perfectly for me. Hope it helps you.
ok, i know is more a django issue but thanks for the reply 😃
this is my
TEMPLATE
setting:with
TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates')
which translates to ‘/home/monadical/pennybags/pennydjango/templates’. And is in thattemplates
folder where I create another foldermapwidgets
and put the templatemy_template.html
.Anyway, I found that I could use javascript triggers to catch the
place_changed
event (which is not explict in docs) and with that I could grab the autocompleted address. That was what I needed in first place.Thanks for the help, is a cool widget 😸