Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1. (Geo Location) Define a data type Location in location. py that repre

ID: 3820397 • Letter: P

Question

Problem 1. (Geo Location) Define a data type Location in location. py that represents a location on Earth using its latitude and longitude. The data type must support t e following API method description Location (lat, lon) a new location l from the given latitude and longitude values the great-circle distance between l and m 1.distanceTo (m) the string representation of l as (lat, lon) str (1) See Problem 7 from Project 2 for the great-circle distance formula. python location py 48.87 -2.33 37.8 122.4 (48.87 2.33) loci (37.8 122.4) lo c2 d (locl, loc2) 8701.38954324 d 111 arccos (sin(a1) sin (z2) cos(z1)cos (a2) cos(yi y2)) Great-Circle Distance Formula import math stdio import import sys class Location Represents a location on Earth def init (self, lat, lon Constructs a new location given its latitude and longitude values self lat self lon def distanceTo (self, other Returns the great-circle distance between self and other def str self Returns a string representation of self Test client DO NOT EDIT Reads floats latl, lonl, lat2, lon2 from command representing two locations on Earth constructs two Location objects from them, and writes them along with the great-circle distance between the two def main lat1, lonl lat2, lon2 map (float sys.argv locl Location (latl, lonl loc2 Location (lat2, lon2 stdio. writeln locl str OC1 stdio writeln loc2 str loc2 str distanceTo(loc2)) stdio writeln d loci, loc2 if name main main

Explanation / Answer

import math
import sys

class Location:
  
   def __init__(self, lat, lon):
       self.lat = lat
       self.lon = lon
      
   def distanceTo(self, other):
       x1, y1, x2, y2 = map(math.radians, [self.lat, self.lon, other.lat, other.lon])
      
       return 111 * math.acos((math.sin(x1) * math.sin(x2))
           + (math.cos(x1) * math.cos(x2) * math.cos(y1 - y2)))
      
   def __str__(self):
       return '(' + str(self.lat) + ', ' + str(self.lon) + ')'
      
  
def main():
   loc1 = Location(48.87, -2.33)
   loc2 = Location(37.8, -122.4)
  
   print('loc1 = ' + str(loc1))
   print('loc2 = ' + str(loc2))
  
   print('Distnce: ' + str(loc1.distanceTo(loc2)))
  
  
main()



I have tried creating the above program as per your question.. but the result doesn't seem promising to me.. Looks like there is some issue with the given formula.. i used the formula given by you but the results are different.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote