Add below to permissions on manifest
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
]
chrome.tabs.getCurrent(function(tab){
console.log(tab.url);
}
);
Alternative for above method.
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
// Do something
});
Add below to permissions on manifest.
"permissions": [
"geolocation"
]
Below promisified method can be used for getting user lat and long information.
function getUserLocationInformation(){
return new Promise(function(resolve, reject){
if(navigator && navigator.geolocation){
navigator.geolocation.getCurrentPosition(
function(geoInfo){
if(geoInfo){
resolve({
lat: geoInfo.coords.latitude,
long: geoInfo.coords.longitude
})
}else{
reject('Unable to fetch geo location');
}
})
}
}
}
Make an ajax call to the below URL to fetch Location information using Lat and Long from above.
latlong_string = '25.033747,121.534620'
http://maps.googleapis.com/maps/api/geocode/json?latlng='+latlong_string+'&sensor=true