0

I have a line between two points and I want to place a marker based on the % of that line, for example.. I've reached 20% of the path, place a marker in that line that corresponds to 20% of the path.

Hows that possible?

Heres my code so far:

var myCenter = new google.maps.LatLng(51.508742, -0.120850);
    function initialize() {
        var mapProp = {
            center: myCenter,
            zoom: 1,
            panControl: true,
            zoomControl: false,
            mapTypeControl: true,
            scaleControl: false,
            streetViewControl: false,
            overviewMapControl: true,
            rotateControl: false,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
        var flightPlanCoordinates = [
            <?php
            $login = $_SESSION['login'];
            $FindIt = $db_account->query("SELECT * FROM main.flights WHERE owner='$login'");
            $counter = $FindIt->rowCount(PDO::FETCH_ASSOC);
            while($route = $FindIt->fetch()){
                $route = $route['route'];
                $Get = $db_account->query("SELECT * FROM main.routes WHERE route='$route'");
                $row = $Get->fetch();
                $departure = $row['start'];
                $arrival = $row['end'];
                //frm
                //((latF-lati)2+(LonF-Longi)2)*44.56
                if($counter == 1){
                    echo "new google.maps.LatLng(".$departure."),";
                    echo "new google.maps.LatLng(".$arrival.")";
                }else{
                    echo "new google.maps.LatLng(".$departure."),";
                    echo "new google.maps.LatLng(".$arrival."),";
                }

            }

            ?>
          ];
        //distance calculations
        var n1
        var myPlane = new google.maps.LatLng();
        var marker = new google.maps.Marker({
            position: myPlane,
            map: map,
            title: 'route name'
          });

        var flightPath = new google.maps.Polyline({
            path: flightPlanCoordinates,
            strokeColor: "#FF0000",
            strokeOpacity: 1.0,
            strokeWeight: 2,
            geodesic: true
        });

        flightPath.setMap(map);
    }
    google.maps.event.addDomListener(window, 'load', initialize);
  • related question: [Calculate the geo position at given time](http://stackoverflow.com/questions/25562799/calculate-the-geo-position-at-given-time) – geocodezip Dec 24 '15 at 15:25
  • possible duplicate of: [latLng from polyLine Percentage](http://stackoverflow.com/questions/19128954/latlng-from-polyline-percentage) – geocodezip Dec 24 '15 at 16:02

0 Answers0