Home >Web Front-end >HTML Tutorial >How to get the latitude and longitude of an address using HTML5 geolocation or Google API?

How to get the latitude and longitude of an address using HTML5 geolocation or Google API?

王林
王林forward
2023-09-20 14:53:021635browse

如何使用HTML5地理定位或Google API获取地址的经纬度?

#In order to get the latitude and longitude using HTML5 Geolocation or any Google API, we need to add JavaScript for this.

The script is as follows -

if (navigator.geolocation) {

   /*  If current position is obtained then there is success otherwise there is failure.
   On failure, separate error message is shown  */    
   navigator.geolocation.getCurrentPosition(successFunc, errorFunc);
}  else {    
   alert(‘Geolocation is not enabled in your browser. Please use a latest browser to supports it.');
}

The above is the detailed content of How to get the latitude and longitude of an address using HTML5 geolocation or Google API?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete