Python Program to Compare User GPS Coordinates with DC Landmarks – Latitude and Longitude Based Location Comparator with Real-World Examples

Build a Python program that asks for user latitude and longitude and compares their location to well-known Washington DC landmarks like the White House, Dupont Circle, and Union Station. Learn how to use basic conditional logic to determine directional relationships using geolocation.

 

Python Program to Compare User GPS Coordinates with DC Landmarks – Latitude and Longitude Based Location Comparator with Real-World Examples

This problem has been solved!

Your friends in the Computer Science department have been complaining to you that DC is confusing to get around. Due to the high cost of their mobile plan's data rates, they can’t use map programs like Apple Maps or Google Maps. They've asked you to build a program that tells users where in DC they are compared to some landmarks that they know. Your task is to build a program which tells user's their relative location to some set places. You should:

  • Ask the user to input their latitude and longitude.
  • Tell the user if they are North of K St. or South of it.
  • If they are North of the White House print “You are north of the White House”. If they are south of the white house print “You are south of the White House”. If they are neither, don’t print anything.
  • If they are west of the White House print “You are north of the White House”. If they are south of the white house print “You are south of the White House”. If they are neither, don’t print anything.
  • Do the same thing with Downing Hall, Dupont Circle, and Union Station

Use the table below as reference:

   

Place

 

Latitude, Longitude

 

K St (Runs east to west)

 

38.902649

 

The White House

 

38.897789, -77.036562

 

Downing Hall

 

38.921669, -77.021361

 

Dupont Circle

 

38.909760, -77.043479

 

Union Station

 

38.897698, -77.007200

Your code should look like this (user input is for Greene Stadium and is in bold):

Insert your latitude: 38.9255998

Insert your longitude: -77.0234159


 Answer

#import math

 

 

def Place (Latitude , Longitude):

    Latitude = float(Latitude)

    Longitude = float(Longitude)

 

    result = ""

   

    if( Latitude >= 38.902649):

        result = result + "You are north of K St" +"\n"

    elif( Latitude < 38.902649 ):

         result = result + "You are south of K St" +"\n"

    else:

        result = result +"\n"

       

    if( Latitude >= 38.897789):

       result = result +"You are north of the White House"+"\n"

    elif( Latitude < 38.897789):

       result = result +"You are south of the White House"+"\n"

    else:

        result = result  +"\n"

 

    if( Longitude >= -77.036562):

       result = result +"You are east of the White House"+"\n"

    elif( Longitude < -77.036562):

        result = result +"You are west of the White House"+"\n"

    else:

        result = result +"\n"

       

   

 

    if( Latitude >= 38.921669):

        result = result +"You are north of Downing Hall"+"\n"

    elif( Latitude < 38.921669):

        result = result +"You are south of Downing Hall"+"\n"

    else:

        result = result +"\n"

 

    if( Longitude >= -77.021361):

        result = result +"You are east of Downing Hall"+"\n"

    elif( Longitude < -77.021361):

        result = result +"You are west of Downing Hall"+"\n"

    else:

        result = result +"\n"

       

   

    if( Latitude >= 38.909760 ):

        result = result +"You are north of Dupont Circle"+"\n"

    elif( Latitude < 38.909760 ):

        result = result +"You are south of Dupont Circle"+"\n"

    else:

        result = result +"\n"

 

    if( Longitude >= -77.043479 ):

        result = result +"You are east of Dupont Circle"+"\n"

    elif( Longitude < -77.043479):

        result = result +"You are west of Dupont Circle"+"\n"

    else:

        result = result +"\n"

       

 

    if( Latitude >= 38.897698):

        result = result +"You are north of Union Station"+"\n"

    elif( Latitude < 38.897698):

        result = result +"You are south of Union Station"+"\n"

    else:

        result = result +"\n"

 

    if( Longitude >= -77.007200 ):

        result = result +"You are east of Union Station"+"\n"

    elif( Longitude < -77.007200 ):

        result = result +"You are west of Union Station"+"\n"

    else:

        result = result +"\n"    

 

    return result

 

def main():

   

    

    Latitude =  input("Pease enter your Latitude: ")

    Longitude =  input("Pease enter your Longitude: ")

 

    output = Place(Latitude , Longitude)

 

    print(output)

 

 

 

 

 

if __name__ == "__main__":

    main()

 

    📩 Need a similar solution? Email me: adel455@hotmail.com

 

Previous Post Next Post

Comments

Nepali Graphics - Learn design, Animation, and Progrmming