Skip to content

Latest commit

 

History

History
75 lines (61 loc) · 1.82 KB

File metadata and controls

75 lines (61 loc) · 1.82 KB

⚠️ This document is aim for older versions (from 2.3.0 to 2.5.3). Document for new version is https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.6.0/README.md

poly.isLocationOnEdge()

Returns true if the position is on edge.

plugin.google.maps.geometry.poly.isLocationOnEdge(position, path);

Parameters

name type description
position ILatLng check position
path ILatLng[] Array of ILatLng

Demo code

<div  id="map_canvas"></div>
var PATH = [
  {lat: 1, lng: 1},
  {lat: -1, lng: -1},
  {lat: 0.3, lng: -0.5},
  {lat: 1.5, lng: 1.2}
];
var mapDiv = document.getElementById("map_canvas");
var map = plugin.google.maps.Map.getMap(mapDiv, {
  'gestures': {
    'scroll': false,
    'tilt': false,
    'rotate': false,
    'zoom': false
  },
  camera: {
    target: PATH
  }
});

// Add polyline
var polyline = map.addPolyline({
  'points': PATH,
  'color' : '#AA00FF',
  'width': 5
});

var marker = map.addMarker({
  'position': (new plugin.google.maps.LatLngBounds(PATH)).getCenter(),
  'draggable': true,
  'title': 'drag me!'
});

// Open the infoWindow
marker.showInfoWindow();

// If the marker position is changed,
// calculates the position is on the edge.
// If on the edge, change the marker color to "blue", otherwise, "red".
marker.on("position_changed", function() {
  var position = marker.getPosition();
  var contain = plugin.google.maps.geometry.poly.isLocationOnEdge(position, PATH);
  marker.setIcon(contain ? "blue" : "red");
});

// Fire the position_changed event for the first calculation
marker.trigger("position_changed", 0, marker.getPosition());