Skip to content

Commit

Permalink
Improved Path Navigator, Now Supports geopositioning resolution (#1917)
Browse files Browse the repository at this point in the history
* Refactored Path Navigator, now supports geopositioning resolution

* Update path example config, for new format

* Fixed typo in dict

* Fixed Ref
  • Loading branch information
asaf400 authored and douglascamata committed Jul 30, 2016
1 parent 0cdbfa2 commit 8b887a1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
11 changes: 4 additions & 7 deletions configs/path.example.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[
{"lng":8.043531775474547,"lat":52.27777834853098},
{"lng":8.045151829719543,"lat":52.27796214757581},
{"lng":8.045924305915833,"lat":52.27753218790187},
{"lng":8.045715093612671,"lat":52.27696437216979},
{"lng":8.044642210006714,"lat":52.27692826803333},
{"lng":8.043639063835144,"lat":52.27722694682294},
{"lng":8.043547868728638,"lat":52.27761095945195}
{"location": "32.087504, 34.806118"},
{"location": "Bialik 150, Ramat Gan"},
{"location": "Ayalon Highway, Ramat Gan"},
{"location": "32.091280, 34.795261"}
]
4 changes: 2 additions & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def _set_starting_position(self):

if self.config.location:
location_str = self.config.location.encode('utf-8')
location = (self._get_pos_by_name(location_str.replace(" ", "")))
location = (self.get_pos_by_name(location_str.replace(" ", "")))
self.api.set_position(*location)
logger.log('')
logger.log(u'Location Found: {}'.format(self.config.location))
Expand Down Expand Up @@ -545,7 +545,7 @@ def _set_starting_position(self):
'initial location...'
)

def _get_pos_by_name(self, location_name):
def get_pos_by_name(self, location_name):
# Check if the given location is already a coordinate.
if ',' in location_name:
possible_coordinates = re.findall(
Expand Down
15 changes: 13 additions & 2 deletions pokemongo_bot/navigators/path_navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ def load_path(self):

def load_json(self, file):
with open(file) as data_file:
return json.load(data_file)
points=json.load(data_file)
# Replace Verbal Location with lat&lng.
logger.log("Resolving Navigation Paths (GeoLocating Strings)")
for index, point in enumerate(points):
if self.bot.config.debug:
logger.log("Resolving Point {} - {}".format(index, point))
point_tuple = self.bot.get_pos_by_name(point['location'])
points[index] = self.lat_lng_tuple_to_dict(point_tuple)
return points

def lat_lng_tuple_to_dict(self, tpl):
return {'lat': tpl[0], 'lng': tpl[1]}

def load_gpx(self, file):
gpx_file = open(file, 'r')
Expand Down Expand Up @@ -82,4 +93,4 @@ def take_step(self):
else:
self.ptr += 1

return [lat, lng]
return [lat, lng]

1 comment on commit 8b887a1

@L422Y
Copy link
Contributor

@L422Y L422Y commented on 8b887a1 Jul 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if coordinates are provided are less than 6-7 decimal points, they are fed to google's geo lookup and then you get an access denied error

Please sign in to comment.