Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds a field to a point feature class containing a link to launch Google Maps with directions from the current location of the device to the destination point.
#
# @author Cindy Jayakumar
#
# @date 12/05/2018
#
# Adds a field to a point feature class containing a link
# to launch Google Maps with directions from the current
# location of the device to the destination point.
#
# Can be used for navigating to sites while in the field,
# using Collector.
#
# No error handling for incorrect geometry type etc
#
import arcpy
# Initialise variables
fc = r"C:\Some\Arb\Folder\test.gdb\points"
# Spatial reference must be WGS 1984
sr = arcpy.SpatialReference(4326)
lyr = arcpy.mp.LayerFile(fc)
try:
arcpy.management.AddField(lyr, "LaunchGoogleMaps", "TEXT",field_length=100)
print("Added field.")
except Exception as e:
print(e)
with arcpy.da.UpdateCursor(lyr, ("SHAPE", "LaunchGoogleMaps"), spatial_reference=sr) as cursor:
for row in cursor:
end = "{0},{1}".format(row[0][1], row[0][0])
row[1] = "https://www.google.com/maps/dir/?api=1&destination={}".format(end)
cursor.updateRow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.