Skip to content

Commit

Permalink
Merge pull request #750 from rshah713/master
Browse files Browse the repository at this point in the history
Add iOS implementation for Maps facade
  • Loading branch information
akshayaurora committed Jul 13, 2023
2 parents 0d4135b + aeac0aa commit 4b811eb
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ implement the api in the easiest way, depending on the current platform.
| IR Blaster || | | | |
| Keystore ||||||
| Light || | | | |
| Maps | | | || |
| Maps | | | || |
| Native file chooser ||||||
| Notifications || ||||
| Orientation || | | ||
Expand Down
2 changes: 1 addition & 1 deletion plyer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@
#: devicename proxy to :class:`plyer.facades.DeviceName`
devicename = Proxy('devicename', facades.DeviceName)

#: Maps proxy to :class: `plyer.facades.Maps`
#: Maps proxy to :class:`plyer.facades.Maps`
maps = Proxy('maps', facades.Maps)
2 changes: 1 addition & 1 deletion plyer/facades/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Supported Platforms
-------------------
macOS
macOS, iOS
---------------
'''

Expand Down
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 4b811eb

Please sign in to comment.