I am wondering how to make an API that lets the user enter a city and then shows them data. For example, if someone entered Huntington, West Virginia or Huntington, WV, they would see the data for Huntington West Virginia.
I have an API developed already, but it always evaluates for Huntington and nothing else. The notebook could also use the IP address as the default and show weather data and geographical data and astronomical data, for example, but so far I haven't been able to figure this out.
How can I make an API that uses the IP address of the visitor to make a map for example?
I have tried changing my IP address with the virtual private network Private Internet Access but it still defaults to Huntington.
Here's my current code:
I have tried using Defer, Delayed, FindGeoLocation, Here, APIFunction, and FormFunction, as well as reading the documentation and reading An Elementary Introduction to Wolfram Language 2nd edition chapter 36 creating websites and apps.
CloudDeploy[
Delayed[
Block[{city}, city = GeoNearest["City", FindGeoLocation[]];
Grid[{{Style["Gravity potential data", "Subsubsection"],
QuantityForm[
UnitConvert[
GeogravityModelData[EntityValue[city, "Position"],
"Potential"], "SIBase"], "Abbreviation"]}, {Style[
"Magnetic magnitude data", "Subsubsection"],
QuantityForm[
UnitConvert[
GeomagneticModelData[EntityValue[city, "Position"],
"Magnitude"], "SIBase"], "Abbreviation"]}, {Style[
"Magnetic north component data", "Subsubsection"],
QuantityForm[
UnitConvert[
GeomagneticModelData[EntityValue[city, "Position"],
"NorthComponent"], "SIBase"], "Abbreviation"]}, {Style[
"Magnetic east component data", "Subsubsection"],
QuantityForm[
UnitConvert[
GeomagneticModelData[EntityValue[city, "Position"],
"EastComponent"], "SIBase"], "Abbreviation"]}, {Style[
"Magnetic down component data", "Subsubsection"],
QuantityForm[
UnitConvert[
GeomagneticModelData[EntityValue[city, "Position"],
"DownComponent"], "SIBase"], "Abbreviation"]}, {Style[
"Magnetic horizontal component data", "Subsubsection"],
QuantityForm[
UnitConvert[
GeomagneticModelData[EntityValue[city, "Position"],
"HorizontalComponent"], "SIBase"], "Abbreviation"]}, {Style[
"Magnetic declination data", "Subsubsection"],
QuantityForm[
UnitConvert[
GeomagneticModelData[EntityValue[city, "Position"],
"Declination"], "SIBase"], "Abbreviation"]}, {Style[
"Magnetic inclination data", "Subsubsection"],
QuantityForm[
UnitConvert[
GeogravityModelData[EntityValue[city, "Position"],
"Inclination"], "SIBase"], "Abbreviation"]}, {Style[
"Magnetic potential data", "Subsubsection"],
QuantityForm[
UnitConvert[
GeomagneticModelData[EntityValue[city, "Position"],
"Potential"], "SIBase"], "Abbreviation"]}, {Style[
"Cloud Cover Fraction Data", "Subsubsection"],
WeatherData[EntityValue[city, "Position"],
"CloudCoverFraction"]}, {Style["Dew Point Data",
"Subsubsection"],
QuantityForm[
UnitConvert[
WeatherData[EntityValue[city, "Position"], "DewPoint"], "SI"],
"Abbreviation"]}, {Style["Pressure Data", "Subsubsection"],
QuantityForm[
UnitConvert[
WeatherData[EntityValue[city, "Position"], "Pressure"], "SI"],
"Abbreviation"]}, {Style["Visibility Data", "Subsubsection"],
QuantityForm[
UnitConvert[
WeatherData[EntityValue[city, "Position"], "Visibility"],
"SI"], "Abbreviation"]}, {Style["Wind Chill Data",
"Subsubsection"],
QuantityForm[
UnitConvert[
WeatherData[EntityValue[city, "Position"], "WindChill"],
"SI"], "Abbreviation"]}, {Style[
"Sun Position Right Ascension and Declination without \
atmospheric refraction corrections", "Subsubsection"],
SunPosition[CelestialSystem -> "Equatorial",
AltitudeMethod -> "TrueAltitude"]}, {Style[
"Moon Position Right Ascension and Declination without \
atmospheric refraction corrections", "Subsubsection"],
MoonPosition[CelestialSystem -> "Equatorial",
AltitudeMethod -> "TrueAltitude"]}, {Style[
"Sun Position Right Ascension and Declination with atmospheric \
refraction corrections", "Subsubsection"],
SunPosition[CelestialSystem -> "Equatorial",
AltitudeMethod -> "ApparentAltitude"]}, {Style[
"Moon Position Right Ascension and Declination with \
atmospheric refraction corrections", "Subsubsection"],
MoonPosition[CelestialSystem -> "Equatorial",
AltitudeMethod -> "ApparentAltitude"]}, {Style[
"Sun Position Azimuth and Altitude without atmospheric \
refraction corrections", "Subsubsection"],
SunPosition[CelestialSystem -> "Horizon",
AltitudeMethod -> "TrueAltitude"]}, {Style[
"Moon Position Azimuth and Altitude without atmospheric \
refraction corrections", "Subsubsection"],
MoonPosition[CelestialSystem -> "Horizon",
AltitudeMethod -> "TrueAltitude"]}, {Style[
"Sun Position Azimuth and Altitude with atmospheric refraction \
corrections", "Subsubsection"],
SunPosition[CelestialSystem -> "Horizon",
AltitudeMethod -> "ApparentAltitude"]}, {Style[
"Moon Position Azimuth and Altitude with atmospheric \
refraction corrections", "Subsubsection"],
MoonPosition[CelestialSystem -> "Horizon",
AltitudeMethod -> "ApparentAltitude"]}, {Style[
"Next upcoming sunrise", "Subsubsection"],
DateString[Sunrise[], "DateTime"]}, {Style[
"Next upcoming sunset", "Subsubsection"],
DateString[Sunset[], "DateTime"]}, {Style[
"Current moon phase with positive or negative sign",
"Subsubsection"],
MoonPhase["SignedFraction"]}, {Style["Current moon phase",
"Subsubsection"],
MoonPhase["Name"]["Name"]}, {Style["Current moon phase icon",
"Subsubsection"],
MoonPhase["Icon"]}, {Style["Next annular solar eclipse",
"Subsubsection"],
DateString[SolarEclipse[EclipseType -> "Annular"],
"DateTime"]}, {Style["Next hybrid solar eclipse",
"Subsubsection"],
DateString[SolarEclipse[EclipseType -> "Hybrid"],
"DateTime"]}, {Style["Next partial solar eclipse",
"Subsubsection"],
DateString[SolarEclipse[EclipseType -> "Partial"],
"DateTime"]}, {Style["Next total solar eclipse",
"Subsubsection"],
DateString[SolarEclipse[EclipseType -> "Total"],
"DateTime"]}, {Style["Next partial lunar eclipse",
"Subsubsection"],
DateString[LunarEclipse[EclipseType -> "Partial"],
"DateTime"]}, {Style["Solar Time", "Subsubsection"],
ToString[SolarTime[]]}, {Style["Sidereal time Time",
"Subsubsection"],
ToString[SiderealTime[]]}, {Style["Julian date",
"Subsubsection"],
Floor@JulianDate[]}, {Style["Map", "Subsubsection"],
GeoGraphics[EntityValue[city, "Position"],
GeoBackground -> "VectorClassic", ImageSize -> Large]}, {Style[
"City Image", "Subsubsection"],
GeoImage[EntityValue[city, "Position"],
ImageSize -> Large]}, {Style["High Resolution Image",
"Subsubsection"],
GeoImage[EntityValue[city, "Position"], GeoZoomLevel -> 15,
ImageSize -> Large]}}, Alignment -> Left]] ],
Permissions -> "Public"]