Get Current Location Google Maps API PHP

Feb 08, 2022 . Admin

Hello Friends,

I am going to explain you example of how to get current location google maps api in PHP. You will learn google maps current location api. In side this article we will see the google maps api current location. This article will give you simple example of how to google maps get current location. We will use google maps api get location.

Showing client side Google Map using Javascript is a simple task. In this tutorial, we are going to see how to get current location of the user. In this example, I used Google Map Javascript API to display map and get current location of the user.

Here i will give you many example of google maps api show current location.

So, let's see bellow solution:

<!DOCTYPE html>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Get Current Location Google Maps Api PHP</title>
        <h2>Get Current Location Google Maps Api php</h2>

        <div id="myMap" style="width:100%;height:500px;"></div>
        let map, infoWindow;

        function initMap() {
          map = new google.maps.Map(document.getElementById("myMap"), {
            center: { lat: -34.397, lng: 150.644 },
            zoom: 6,
          infoWindow = new google.maps.InfoWindow();

          const locationButton = document.createElement("button");

          locationButton.textContent = "Move to Current Location";
          locationButton.addEventListener("click", () => {
            // Try HTML5 geolocation.
            if (navigator.geolocation) {
                (position) => {
                  const pos = {
                    lat: position.coords.latitude,
                    lng: position.coords.longitude,

                  infoWindow.setContent("Location found.");
                () => {
                  handleLocationError(true, infoWindow, map.getCenter());
            } else {
              // Browser doesn't support Geolocation
              handleLocationError(false, infoWindow, map.getCenter());

        function handleLocationError(browserHasGeolocation, infoWindow, pos) {
              ? "Error: The Geolocation service failed."
              : "Error: Your browser doesn't support geolocation."
        <script src=""></script>

It will help you...