ionic-team / ionic-native-google-maps

Google maps plugin for Ionic Native
Other
221 stars 125 forks source link

isLocationOnEdge always returning false #177

Closed omkarkhalipe closed 5 years ago

omkarkhalipe commented 5 years ago

I'm submitting a ... (check one with "x")

If you choose 'problem or bug report', please select OS: (check one with "x")

cordova information: (run $> cordova plugin list)

insert the output from the command here

If you use @ionic-native/google-maps, please tell the package.json (only @ionic-native/core and @ionic-native/google-maps are fine mostly)

Current behavior:

I am trying to check if lat,lon is on polyline but no matter what I do isLocationOnEdge always returns false, even for direction polyline, I able to draw polyline but not able to test if coordinate is on polyline

Expected behavior:

Screen capture or video record:

Related code, data or error log (please format your code or data):

 polyline.on(GoogleMapsEvent.POLYLINE_CLICK).subscribe((params: any) => {
      let position: LatLng = <LatLng>params[0];
     console.log("test"+ Poly.isLocationOnEdge(position,AIR_PORTS));

      let marker: Marker = this.map.addMarkerSync({
        position: position,
        title: position.toUrlValue(),
        disableAutoPan: true
      });
      marker.showInfoWindow();
    });
wf9a5m75 commented 5 years ago

Please share your project files on github repository.

omkarkhalipe commented 5 years ago

https://github.com/omkarkhalipe/ionic-map-bug

omkarkhalipe commented 5 years ago

did you get a chance to check it? It would be great if you could provide a example for isLocationOnEdge()

wf9a5m75 commented 5 years ago

My private time is limited. Thus, free support is low priority.

wf9a5m75 commented 5 years ago

I checked the implementation code, and isLocationOnEdge() always false is correct.

The reason is latLng is not on the polyline.

Finger is bigger than mouse pointer. Thus, even click on polyline, most cases are not on polyline. That's why polyline has margin.

For example, you can click on 1px polyline, but it's really difficult exactly on the 1px width polyline. That's why plugin access +-10px.

Then plugin sends the event with original touched lat/lng, which is not on the polyline.

omkarkhalipe commented 5 years ago

Basically I am checking if point is on polyline when clicked on polyline polyline.on(GoogleMapsEvent.POLYLINE_CLICK)

Also I tried to increase width, but same result

` let polyline: Polyline = this.map.addPolylineSync({ points: AIR_PORTS, color: '#AA00FF', width: 40, geodesic: true, clickable: true // clickable = false in default });

polyline.on(GoogleMapsEvent.POLYLINE_CLICK).subscribe((params: any) => {
  let position: LatLng = <LatLng>params[0];
 alert("test"+ Poly.isLocationOnEdge(position,AIR_PORTS));
 console.log("test"+ Poly.isLocationOnEdge(position,AIR_PORTS));

let marker: Marker = this.map.addMarkerSync({ position: position, title: position.toUrlValue(), disableAutoPan: true }); marker.showInfoWindow(); });`

The marker is added correctly on polyline though. simulator screen shot - iphone x - 2019-02-17 at 09 59 14

wf9a5m75 commented 5 years ago

Please check the code how to implement. This plugin is fully open source code. If you can't satisfy implementation, please send a pull request.

wf9a5m75 commented 5 years ago

Here you are. Code is fully written in JavaScript. https://github.com/mapsplugin/cordova-plugin-googlemaps/blob/master/www/poly.js

wf9a5m75 commented 5 years ago

Since the code is written in JavaScript, you can understand the code logic. As you can see, isLocationOnEdge does not consider polyline.width because the second argument is path not polyline. Thus, the isLocationOnEdge returns always false. This is not a bug.

I prefer the person who do his/her best, not just pushing his/her opinion. At least you should read the code.