Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김동훈
/
OpenSource_Project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
1
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Donghoon Kim
2018-12-05 23:19:29 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
f744f6b9edb43e51188c059b49f0f6962baf9e33
f744f6b9
2 parents
e0dc611b
f15429a8
Merge branch 'api'
merge api.js file to master
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
api.js
api.js
0 → 100644
View file @
f744f6b
// set environment variables
//export GOOGLE_PLACES_API_KEY = "AIzaSyAFbdNtVeHHzP0RYu9efx6QLCgbMK1dzP0"
//export GOOGLE_PLACES_OUTPUT_FORMAT = "json"
// var assert = require("assert");
/*
const googleMapsClient = require('@google/maps').createClient({
key: 'AIzaSyAFbdNtVeHHzP0RYu9efx6QLCgbMK1dzP0'
});
// Geocode an address.
googleMapsClient.geocode({
address: '1600 Amphitheatre Parkway, Mountain View, CA'
}, function(err, response) {
if (!err) {
console.log(response.json.results);
}
});
*/
// google place api 연동
// exports.apiKey = process.env.GOOGLE_PLACES_API_KEY;
// exports.outputFormat = process.env.GOOGLE_PLACES_OUTPUT_FORMAT
function
ipLookUp
()
{
$
.
ajax
(
'http://ip-api.com/json'
)
.
then
(
function
success
(
response
)
{
console
.
log
(
'User\'s Location Data is '
,
response
);
console
.
log
(
'User\'s Country'
,
response
.
country
);
getAdress
(
response
.
lat
,
response
.
lon
)
},
function
fail
(
data
,
status
)
{
console
.
log
(
'Request failed. Returned status of'
,
status
);
}
);
}
function
getAddress
(
latitude
,
longitude
)
{
$
.
ajax
(
'https://maps.googleapis.com/maps/api/geocode/json?'
+
'latlng='
+
latitude
+
','
+
longitude
+
'&key='
+
AIzaSyAFbdNtVeHHzP0RYu9efx6QLCgbMK1dzP0
)
.
then
(
function
success
(
response
)
{
console
.
log
(
'User\'s Address Data is '
,
response
)
},
function
fail
(
status
)
{
console
.
log
(
'Request failed. Returned status of'
,
status
)
}
)
}
if
(
"geolocation"
in
navigator
)
{
// check if geolocation is supported/enabled on current browser
navigator
.
geolocation
.
getCurrentPosition
(
function
success
(
position
)
{
// for when getting location is a success
console
.
log
(
'latitude'
,
position
.
coords
.
latitude
,
'longitude'
,
position
.
coords
.
longitude
);
getAddress
(
position
.
coords
.
latitude
,
position
.
coords
.
longitude
)
},
function
error
(
error_message
)
{
// for when getting location results in an error
console
.
error
(
'An error has occured while retrieving'
+
'location'
,
error_message
)
ipLookUp
()
});
}
else
{
// geolocation is not supported
// get your location some other way
console
.
log
(
'geolocation is not enabled on this browser'
)
ipLookUp
()
}
\ No newline at end of file
Please
register
or
login
to post a comment