Skip to content

Commit e1732c2

Browse files
committed
Utilize geolocation API
1 parent fbb3852 commit e1732c2

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/components/Create.vue

+19-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Just set your location and search radius, then we'll create a room you can invite your friends to. NomNom will take care of the rest!
1111
</p>
1212
<v-flex xs12>
13-
<v-text-field v-model="searchLocation" label="Enter a Zipcode, City or Address" required></v-text-field>
13+
<v-text-field v-model="searchLocation" append-icon="gps_fixed" :success=gotLocation @click:append="getLocation()" label="Enter a Zipcode, City or Address" required></v-text-field>
1414
<v-subheader class="pl-0">Search Radius (miles)</v-subheader>
1515
<v-slider
1616
v-model="rangeRadius"
@@ -36,15 +36,29 @@ export default {
3636
data() {
3737
return {
3838
searchLocation: '',
39-
rangeRadius: 10
40-
}
39+
rangeRadius: 10,
40+
gpsPosition: false,
41+
gotLocation: false,
42+
};
4143
},
4244
methods: {
4345
handleCreateRoom() {
44-
makeRoom(this.searchLocation, this.rangeRadius).then((resp) => {
46+
makeRoom(this.searchLocation, this.rangeRadius, this.gpsPosition).then((resp) => {
4547
this.$router.push(`/nom/${resp.data.roomId}`);
4648
});
4749
},
50+
geoLocationSuccess(position) {
51+
console.log(position);
52+
const { coords: { latitude, longitude } } = position;
53+
this.searchLocation = 'Your GPS position';
54+
this.gpsPosition = { latitude, longitude };
55+
this.gotLocation = true;
56+
},
57+
getLocation() {
58+
if (navigator && navigator.geolocation) {
59+
navigator.geolocation.getCurrentPosition(this.geoLocationSuccess, (error) => { console.log(error); }, { enableHighAccuracy: true, timeout: 5000 });
60+
}
61+
},
4862
},
4963
};
50-
</script>
64+
</script>

src/services/nomService.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { getNick } from './auth';
44
// const apiRoot = 'http://localhost:8088';
55
const apiRoot = 'http://142.93.118.93:8088';
66

7-
export function makeRoom(searchLocation, searchRadius) {
8-
return axios.post(`${apiRoot}/makeroom`, { user: getNick(), searchLocation, searchRadius });
7+
export function makeRoom(searchLocation, searchRadius, gpsPosition) {
8+
return axios.post(`${apiRoot}/makeroom`, { user: getNick(), searchLocation, searchRadius, gpsPosition });
99
}
1010

1111
export function getNomsForUser(roomId) {

0 commit comments

Comments
 (0)