This is new post

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras varius facilisis nisi sed iaculis. Nullam tristique vitae quam id aliquam. Integer id vulputate metus. Duis quis nulla eu urna posuere bibendum in et nisl. Mauris elementum vehicula massa nec tristique. Morbi viverra, metus vitae dapibus consequat, lectus mi vestibulum urna, in pellentesque lacus leo sit amet dui. Quisque ante dui, vehicula in hendrerit at, vehicula nec nisi. In metus purus, sollicitudin sit amet malesuada in, sodales ac lorem. Nulla vel metus quis ligula lobortis placerat. Vestibulum sed turpis suscipit, semper nisl sit amet, suscipit ex. Donec sodales massa et posuere vulputate. Morbi efficitur augue velit, sit amet vestibulum ligula facilisis ac. In ut turpis eu orci aliquet luctus.

Praesent consequat, risus eget commodo tempus, erat tortor feugiat erat, ut pulvinar est ante in massa. Nam metus ipsum, laoreet nec lorem ac, hendrerit rutrum ligula. Aliquam interdum, dui eu viverra lacinia, turpis lorem dapibus purus, in aliquam dolor metus nec ex. Ut quis velit id nibh viverra ornare sit amet in erat. Morbi bibendum, mauris vel gravida egestas, risus risus finibus nibh, et vestibulum tortor nulla a dolor. Etiam auctor at mauris et venenatis. Maecenas cursus tincidunt libero, interdum convallis ligula bibendum at.

 

// Replace YOUR_API_KEY with your actual Google Maps API key
const apiKey = 'AIzaSyBgYefjACp4jnX810jepsq9YMN0E5ZONHE';

// Get the user's current location
function getCurrentLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(getDestinationLocation, handleError);
  } else {
    console.error('Geolocation is not supported by this browser.');
  }
}

// Get the destination location from the user's search
function getDestinationLocation(position) {
  const currentLat = position.coords.latitude;
  const currentLng = position.coords.longitude;
  const destination = prompt('Enter destination location:');

  // Construct the URL for Place Autocomplete API
  const autocompleteUrl = `https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=${destination}&inputtype=textquery&fields=geometry&key=${apiKey}`;

  // Fetch the data from the Place Autocomplete API
  fetch(autocompleteUrl)
    .then(response => response.json())
    .then(data => {
      const destinationLat = data.candidates[0].geometry.location.lat;
      const destinationLng = data.candidates[0].geometry.location.lng;
      calculateDistance(currentLat, currentLng, destinationLat, destinationLng);
    })
    .catch(error => {
      console.error('Error fetching destination data:', error);
    });
}

// Calculate the distance between current and destination locations
function calculateDistance(currentLat, currentLng, destinationLat, destinationLng) {
  // Construct the URL for the Directions API
  const apiUrl = `https://maps.googleapis.com/maps/api/directions/json?origin=${currentLat},${currentLng}&destination=${destinationLat},${destinationLng}&key=${apiKey}`;

  // Fetch the data from the Directions API
  fetch(apiUrl)
    .then(response => response.json())
    .then(data => {
      // Extract the distance from the response
      const distance = data.routes[0].legs[0].distance.text;
      document.getElementById('distance').innerText = `Distance: ${distance}`;
    })
    .catch(error => {
      console.error('Error fetching data:', error);
    });
}

function handleError(error) {
  console.error('Error getting user location:', error);
}

// Call the getCurrentLocation function to start the process
getCurrentLocation();

 

Suspendisse quis laoreet orci, nec cursus ex. Aenean vel rhoncus mauris, eu rhoncus dolor. Phasellus id arcu lectus. Proin ut lorem gravida, rutrum lorem vel, aliquet augue. Donec eu dui libero. Quisque non mattis est, quis tempus enim. Vestibulum at mauris eu mauris porta varius vel imperdiet nisl.

In hac habitasse platea dictumst. Donec id auctor neque, eu auctor ipsum. Curabitur dictum tristique mauris, ut aliquam augue feugiat id. Duis tincidunt, velit id accumsan tincidunt, lectus leo placerat ante, ut dictum turpis mauris at ante. Nam tincidunt ipsum in sem sodales porttitor. Cras non tortor sit amet erat tincidunt auctor nec vitae lectus. Morbi a commodo nulla, ut porttitor justo. Nunc dignissim faucibus orci, ac dictum justo egestas sollicitudin. Sed nec quam tortor. Sed finibus eget sapien ut semper. Morbi elit libero, cursus sed porta sed, facilisis at ligula.

Sed bibendum tempor ex vel viverra. Nullam fermentum dolor at ante pharetra, nec efficitur orci dignissim. Aliquam tempus ligula ultrices est aliquam, et volutpat neque tincidunt. Praesent sagittis, libero sed consectetur pretium, ipsum urna viverra justo, id pellentesque tellus dui a tellus. Aenean convallis nisl massa, a elementum diam lacinia finibus. Vivamus feugiat aliquam diam ac congue. Praesent et risus id dui volutpat pellentesque non in nibh. Suspendisse at elit ac magna vehicula aliquet sed sit amet arcu.

Tags

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

Related articles

Contact us

Partner with Us for Exceptional IT Solutions

We’re happy to answer any questions you may have and help you determine which of our services best fit your needs.

Your benefits:
What happens next?
1

We schedule a call at your convenience 

2

We perform an in-depth analysis of your requirements

3

We prepare a proposal 

Schedule a Free Consultation