LoginSignup
0

More than 3 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>

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
What you can do with signing up
0