Home reactjs REACT-YANDEX-MAPS Obtaining the nearest coordinates relative to the marker

REACT-YANDEX-MAPS Obtaining the nearest coordinates relative to the marker

Author

Date

Category

Actually the problem is the following, React Ya Map documentation is not very good for rarity. It is necessary to obtain the coordinates of the nearest point at MKAD on the marker. The polygon is respectively created, it is necessary to call some kind of method. There is a GetClosestPoint method at ymaps, but it does not turn it out … I really hope for your help friends! Thank you.

import {ymaps, map, placemark, polygon} from 'react-yandex-maps';
    Class YMAP EXTENDS REACT.COMPONENT {
      STATE = {
        marker: [],
        markeraddress: ""
      }
      YMAPS: Any.
      Polygon: Any.
      geocode () {// Get the address by the coordinates of the installed marker and display in the Notiffikeynes.
        this.ymaps.geocode (this.state.Marker)
          .Then ((Result: Any) = & gt; this.setstate ({markeraddress: result .geoobjects.get (0) .getAdDressLine ()}))
          .then (() = & gt; {
            Store.AddNotification ({// Create Notiffikeyshn
              Title: "Address",
              Message: this.state.markeraddress,
              Type: "info",
              INSERT: "TOP",
              CONTAINER: "TOP-RIGHT",
              Animationin: ["animate__animated", "animate__fadein"],
              AnimationOut: ["animate__animated", "animate__fadeout"],
              Dismiss: {
                Duration: 5000,
                OnScreen: True.
              }
            })
          })
      }
      render () {
        Return (
          & lt; ymaps
            query = {{apikey: 'my-api-key'}}
            & gt;
            & lt; reactnotification / & gt;
            & lt; map
              modules = {['geocode']}
              DefaultState = {{center: [55.75, 37.57], zoom: 9}}
              width = {"100%"}
              Height = {"100vh"}
              OnClick = {(Event: Any) = & gt; {// Install the marker and write down the coordinates in the step
                This.SetState ({Marker: Event.get ('Coords')})
                This.Geocode () // Displays the address
              }}
              ONLOAD = {(YMAPS: Any) = & gt; this.ymaps = ymaps}
            & gt;
              & lt; Polygon
                geometry = {Moscow.coordates} // Coordinates in File JSON.
                Options = {{Visible: false}}
              / & gt;
              {this.state.marker & amp; & amp;
                & lt; placemark
                  geometry = {this.state.marker}
                / & gt;}
            & lt; / map & gt;
          & lt; / ymaps & gt;
        );
      }
    }

Answer 1

To use Yandex Maps Methods you need to take InstanceRef Your card (Description: https://react-yandex-maps.now.sh/map )

& lt; map defaultstate = {{center: [50, 20], zoom: 10, controls: ['zoom'] }} width = "100%" height = "100%" instanceref = {ref = & gt; (this.mymap = ref)} / & gt;

Next You are in this.mymap you can already use Yandex Card Methods


Answer 2

Running in the instance of the landfill found the GetCloses () method, it is not getcloseSpoint (), but returns also the nearest point! It looks like a solution to the problem.
Ultimately looks like this:

& lt; polygon
InstanceRef = {(Ref) = & gt; this.polygoninst = Ref}
geometry = {Moscow.coordinates}
Options = {{Visible: false}}
/ & gt; 
console.log (this.polygonInst.geometry.getClosest (this.state.marker))

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions