Lars
Lars

Reputation: 1270

Accessing User Location ( Only City Name ) ( NOT Map )

I am building a BlogApp and I am stuck on a Problem.

What i am trying to do

I am trying to access user location like :- City or State. I don't want to access in Map. I just want to access the city name of users.

What have i tried

I don't know what to do.

Any help would be appreciated.

Thank You in Advance.

Upvotes: 0

Views: 266

Answers (2)

koko
koko

Reputation: 397

  1. I think you cant start new ajax as success after first one. In this case after first ajax is done you should write City on the page element.
  2. After you got element with City on page, you can try to initiate new ajax for changing element
$( "<your element with City name>" ).change(function() {
      const city = <something where you wrote your City>;
        $.ajax ({
        url : <your url>,
        data: {
                'city': city,
            },
        success: function (data) {
                <do something if you want>;
            }
        });
    });
  1. Django: you can read this for understanding ajax (I just googled it). In simple words, you initiate ajax to your server(you create url point for it), for that url you create function to save data to db. (Sorry for my english)

url:

...
path('<your url>', views.your_function, name='ajax-something'),
...

views:

def your_function(request):
     city = request.GET.get('city')
     <here you write data to db>

     return <what you want to do>

Upvotes: 1

Chymdy
Chymdy

Reputation: 660

Use Ajax.

After getting your location. Use Ajax to send it to django and them use django to save to db.

Upvotes: 0

Related Questions