0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vue.js で 緯度経度から住所を取得

Last updated at Posted at 2019-01-29

都道府県を取得したいだけなので、マップは使わない。

上記をインストールして、コードはこれ。


<script>
        created() {
            
            if (navigator.geolocation){

                navigator.geolocation.getCurrentPosition((position) => {

                    Vue.$geocoder.setDefaultMode('lat-lng');
                    
                    var latLngObj = {
                        lat: position.coords.latitude,
                        lng: position.coords.longitude
                    };

                    let res = Vue.$geocoder.send(latLngObj, response => {

                        let d = response.results.splice(-2,1);
                        this.pref = d[0]['address_components'][0]['long_name'];//愛知県
                    });
                });


            } else {
                //alert('非対応ブラウザ');
            }

        },
</script>

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?