allenhwkim / angularjs-google-maps

The Simplest AngularJS Google Maps V3 Directive
http://ngmap.github.io
MIT License
1.52k stars 517 forks source link

Handle impossible driving directions #739

Open langdonx opened 7 years ago

langdonx commented 7 years ago

If you provide 2 points that are separated by water and impossible to drive to or walk to, you end up staring at a map of San Francisco:

http://plnkr.co/edit/UPoGrXrT6MS5kqDuAjTk?p=preview

This doesn't seem to be handled by the directive currently.

Is there some sort of callback I can subscribe to to handle this ~error myself? I'd like to at least gray out the map and inform the user that directions between the two points are not possible at this time or something.

allenhwkim commented 7 years ago

As it is specified here, DirectionsService returns result https://developers.google.com/maps/documentation/javascript/directions

However, ng2-map only handles the OK result at the moment. For errors, we need to improve it to handle error result too.

https://github.com/allenhwkim/angularjs-google-maps/blob/master/directives/directions.js#L67

langdonx commented 7 years ago

Thanks for the quick reply! I'm still using Angular 1 and will be for the foreseeable future.

Do you accept pull requests? It looks like you can tell something went wrong if the DirectionsService returns back status: "ZERO_RESULTS" instead of status: "OK".

How do your other directives handle errors? An attribute callback? Or should the directive itself display the error saying directions cannot be processed?

allenhwkim commented 7 years ago

Yes I accept PR. About error handling, you can follow normal event handling, or take a look at how map directive handles the error.