Here I'm using this Places API in my project to find the locations of user but when I click on the field popup is opening as know your location by giving two options allow and block but client don't want that popup to be open it always allow the user to know the location. is there any option in the api to do this functionality.
Asked
Active
Viewed 2,544 times
-1
1 Answers
0
Here is the documentation for your answer.
Just ask for permission as a clear response to a user gesture.
Create a button for user to allow device location, then;
var usermarkers = [];
var userMarker;
function geolocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
userLat = position.coords.latitude;
userLng = position.coords.longitude;
currentloc = { lat: userLat, lng: userLng };
var userSerial = "987654321";
for (var i = 0; i < usermarkers.length; i++) {
if (usermarkers[i].serialNumber === userSerial) {
usermarkers[i].setMap(null);
usermarkers = [];
}
}
userMarker = new google.maps.Marker({
position: currentloc,
map: map,
serialNumber: userSerial
});
userMarker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png')
usermarkers.push(userMarker);
calculateDistance(ppath);
});
} else {
alert("Error: Your browser doesn\'t support geolocation.");
}
}
I also added marker remove for next calls. Hope this helps.

Mapster
- 88
- 1
- 14
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/20606758) – Patrick Mevzek Aug 16 '18 at 15:40
-
1@PatrickMevzek It is Google's documentation! The link has all necessary approaches including code. Why would I retype the code since link has it. I didn't provide 3rd party link. – Mapster Aug 16 '18 at 16:21
-
1Your link goes to `developers.google.com` while we are on `stackoverflow.com`, so it is indeed a 3rd party link. Please have a look at https://stackoverflow.com/help/how-to-answer and specifically this part: *Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.* Your answer needs to remain valid just as is with its content, even if the link go stale. – Patrick Mevzek Aug 16 '18 at 17:40
-
@ganesh was this the answer you were looking for? – Mapster Aug 19 '18 at 21:24