Skip to content

Commit

Permalink
navigator icon added
Browse files Browse the repository at this point in the history
  • Loading branch information
rithasahmed12 committed Mar 9, 2024
1 parent c7bff28 commit cb0594f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Binary file modified curr-start-indicator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 19 additions & 13 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
var mapOptions = {};
var map;
var currMarker;
var marker;
var desMarker;

var startIcon = {
url: 'curr-start-indicator.png', // Path to your custom icon image
scaledSize: new google.maps.Size(40, 40), // Size of the icon
}

var currentIcon = {
url: 'current-indicator.png', // Path to your custom icon image
scaledSize: new google.maps.Size(40, 40), // Size of the icon
}



Expand All @@ -13,7 +22,6 @@ if (navigator.geolocation) {
}

function success(position) {
console.log('lalala:', position);
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;

Expand All @@ -29,10 +37,6 @@ function success(position) {
// Create the map
map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);

var currentIcon = {
url: 'current-indicator.png', // Path to your custom icon image
scaledSize: new google.maps.Size(40, 40), // Size of the icon
}


// Create a marker for the current location
Expand All @@ -57,16 +61,16 @@ function success(position) {
}

function addPinMarker(event){
if(marker){
marker.setMap(null)
if(desMarker){
desMarker.setMap(null)
}

var endIcon = {
url: 'end-indicator.png', // Path to your custom icon image
scaledSize: new google.maps.Size(30, 40), // Size of the icon
}

marker = new google.maps.Marker({
desMarker = new google.maps.Marker({
position: event.latLng,
map: map,
title: 'Destination',
Expand Down Expand Up @@ -188,14 +192,16 @@ function trackUser(position) {
currMarker.setPosition({ lat: latitude, lng: longitude });
} else {
// Create user marker if not already created
marker = new google.maps.Marker({
currMarker = new google.maps.Marker({
position: { lat: latitude, lng: longitude },
map: map,
title: 'Your Location',
icon: currentIcon
});
}

currMarker.setIcon(startIcon);

// Check if user has reached the destination
const destination = document.getElementById("to").value;
const distanceToDestination = google.maps.geometry.spherical.computeDistanceBetween(new google.maps.LatLng(latitude, longitude), destination);
Expand Down Expand Up @@ -239,14 +245,14 @@ function stopLiveTracking() {
}
document.getElementById('start-btn').style.display = 'block'
document.getElementById('stop-btn').style.display = 'none'

currMarker.setIcon(currentIcon);
// Clear the directions displayed on the map
directionsDisplay.setDirections({ routes: [] });

// Remove the destination marker from the map
if (marker) {
marker.setMap(null);
marker = undefined; // Reset marker variable
desMarker.setMap(null);
desMarker = undefined; // Reset marker variable
}
}

Expand Down

0 comments on commit cb0594f

Please sign in to comment.