Skip to content

Commit

Permalink
Add iOS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rshah713 authored Mar 11, 2023
1 parent 36ce4f4 commit bcba3f3
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions plyer/platforms/ios/maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'''
Module of iOS API for plyer.maps.
'''

import webbrowser
from plyer.facades import Maps
from urllib.parse import quote_plus


class iOSMaps(Maps):
'''
Implementation of iOS Maps API.
'''

def _open_by_address(self, address, **kwargs):
'''
:param address: An address string that geolocation can understand.
'''

address = quote_plus(address, safe=',')
maps_address = 'http://maps.apple.com/?address=' + address

webbrowser.open(maps_address)

def _open_by_lat_long(self, latitude, longitude, **kwargs):
'''
Open a coordinate span denoting a latitudinal delta and a
longitudinal delta (similar to MKCoordinateSpan)
:param name: (optional), will set the name of the dropped pin
'''

name = kwargs.get("name", "Selected Location")
maps_address = 'http://maps.apple.com/?ll={},{}&q={}'.format(
latitude, longitude, name)

webbrowser.open(maps_address)

def _search(self, query, **kwargs):
'''
:param query: A string that describes the search object (ex. "Pizza")
:param latitude: (optional), narrow down query within area,
MUST BE USED WITH LONGITUDE
:param longitude: (optional), narrow down query within area,
MUST BE USED WITH LATITUDE
'''

latitude = kwargs.get('latitude')
longitude = kwargs.get('longitude')

query = quote_plus(query, safe=',')
maps_address = 'http://maps.apple.com/?q=' + query

if latitude is not None and longitude is not None:
maps_address += '&sll={},{}'.format(latitude, longitude)

webbrowser.open(maps_address)

def _route(self, saddr, daddr, **kwargs):
'''
:param saddr: can be given as 'address' or 'lat,long'
:param daddr: can be given as 'address' or 'lat,long'
'''
saddr = quote_plus(saddr, safe=',')
daddr = quote_plus(daddr, safe=',')

maps_address = 'http://maps.apple.com/?saddr={}&daddr={}'.format(
saddr, daddr)
webbrowser.open(maps_address)


def instance():
'''
Instance for facade proxy.
'''
return iOSMaps()

0 comments on commit bcba3f3

Please sign in to comment.