Avatar

Drop pins on the map

0

So we have a method to write zones to the map, is there a way to write individual pins?

Example: I work for a 911 ambulance service.  We want to take a list of addresses from the computer aided dispatch system, geocode them, and then draw individual pins on the map expiring in a certain time period.  I have the code to geocode the addresses into coordinates, and I have worked with some pseudocode to add zones to the map, but I was wondering if there is a way to add a pin instead of a zone.  

 

Code: 

data = {'addresses':['3930 Georgetown Road, Indianapolis, Indiana, 46254']}
coordinates = api.call('GetCoordinates', **data)
test2 = {'coordinates':coordinates}
addZone = {'typeName':'Zone', 'entity':{'name':'Dispatch Address, 'activeFrom':'2018-11-12T15:45:00Z', 'activeTo': '2018-11-12T16:45:00Z','points':test2}}
test4 = api.call('Add', **addZone)

Thanks in advance, as always!

Jeremiah Cook

Please sign in to leave a comment.

4 comments

0
Avatar

Hi Jeremiah,

Currently, there is no way to create a pin on the map at a given location. I think you are on the right track with zones.

Thanks,

Steve

Steve Hansen 0 votes
0
Avatar

zone = {'typeName':'Zone', 'entity':{'name':'Dispatch Address', 'activeFrom':'2018-11-12T15:45:00Z', 'activeTo': '2018-11-12T16:45:00Z', 'points':test2}}
test = api.call('Add', **zone)

Getting an exception, u0027, Geotab.Serialization.JsonSerializerException.  Anyone got any ideas on how to fix?

Jeremiah

Jeremiah Cook 0 votes
0
Avatar

`points` looks incorrect. Expected to be an array of coordinates:

...`points`:{'coordinates': coordinates}, vs ...`points`: coordinates,

Also, points should comprise a polygon instead of a single point. The import zones example shows how to create a square zone from point and size.

I think you will also need to include a group for the zone. Ex: 'groups': [{'id': 'GroupCompanyId'}],

Here's sample code as tested.

Steve Hansen 0 votes
0
Avatar

Here's the revised Python code that works like a charm.  Thanks to Steve for his guidance!

def toDegrees(radians):
return radians * 180.0 / math.pi

def toRadians(degrees):
return degrees * (math.pi/180.0)

def generateZonePoints(latitude, longitude, size):
earthRadius = 20903520
x1 = (longitude - toDegrees(size/earthRadius / math.cos(toRadians(latitude))))
x2 = (longitude + toDegrees(size/earthRadius / math.cos(toRadians(latitude))))
y1 = (latitude + toDegrees(size/earthRadius / math.sin(toRadians(longitude))))
y2 = (latitude - toDegrees(size/earthRadius / math.sin(toRadians(longitude))))
return[
{'x': x1, 'y': y1},
{'x': x2, 'y': y1},
{'x': x2, 'y': y2},
{'x': x1, 'y': y2}
]

data = {'addresses':['3930 Georgetown Road, Indianapolis, Indiana, 46254']}
coordinates = api.call('GetCoordinates', **data)
points = generateZonePoints(coordinates[0]['y'], coordinates[0]['x'], 10)
utcTime = datetime.utcnow()
utcTimestamp = utcTime.strftime('%m/%d/%Y')
print(utcTime)
utcPlusOne = datetime.utcnow() + timedelta(minutes=10)
print (utcPlusOne)

zone = {'typeName':'Zone', 'entity':{'name':'Dispatch Address '+ utcTimestamp, 'activeFrom':utcTime, 'activeTo': utcPlusOne , 'points':points, 'groups':[{'id':'GroupCompanyId'}]}}
test = api.call('Add', **zone)

Jeremiah Cook 0 votes