This is VB code that add 2 markers, draw a straight polyline between the markes and then make a GoogleMap directions route.
If you need you can convert VB to C# or vice versa here http://converter.telerik.com/
ASPX page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <%@ Page Title="" Language="C#" MasterPageFile="Markers.master" AutoEventWireup="false" CodeBehind="CodeBehind.aspx.cs" Inherits="GoogleMaps.Samples.Markers.CodeBehind" %> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <h2> Markers Code Behind </h2> <p> GoogleMap control markers code behind sample. </p> <div class="map-wrap"> <map:GoogleMap ID="GoogleMap1" runat="server" Latitude="42.1229" Longitude="24.7879" Zoom="6" EnableScrollWheelZoom="true" CssClass="map" Width="100%" Height="600px" FullscreenControl="true"> </map:GoogleMap> </div> </asp:Content> |
Codebehind
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | Dim point1 As GoogleMaps.LatLng Dim point2 As GoogleMaps.LatLng Dim polyline As New GoogleMaps.Polylines.GooglePolyline() Dim wayplot As New GoogleMaps.Directions.GoogleDirections Dim wayloc As New GoogleMaps.Polygons.GooglePolygon point1 = New GoogleMaps.LatLng(58.3, 14.28) point2 = New GoogleMaps.LatLng(57.7, 11.9666) Dim car As New GoogleMaps.Markers.Marker Dim car1 As New GoogleMaps.Markers.MarkerImage() car1 = "http://labs.google.com/ridefinder/images/mm_20_red.png" car.Position = point1 car.Title = "Johans car on Arlanda airport 20161213" car.Icon = car1 car.Draggable = True car.Animation = True car.Clickable = True car.Shadow = True Dim car3 As New GoogleMaps.Markers.Marker Dim car4 As New GoogleMaps.Markers.MarkerImage() car1 = "http://labs.google.com/ridefinder/images/mm_20_green.png" car3.Position = point2 car3.Title = "Johans car on Arlanda airport 20161213" car3.Icon = car4 car3.Draggable = True car3.Animation = True car3.Clickable = True car3.Shadow = True polyline.Path.Add(point1) polyline.Path.Add(point2) polyline.StrokeWeight = 5 polyline.StrokeColor = Color.Red Dim Markercontent As New StringBuilder Markercontent.Append("<h3>Starting point</h3><br><img src='https://googlemapcontrol.com/wp-content/uploads/2017/07/velio.jpg' height='100' width='100'></p>") car.Info = Markercontent.ToString Dim Markercontent1 As New StringBuilder Markercontent1.Append("<h3>End point</h3><br><img src='https://googlemapcontrol.com/wp-content/uploads/2017/07/johan.jpg' height='100' width='100'></p>") car3.Info = Markercontent1.ToString 'Directions Dim destination As String = "Hjo, sweden" Dim origin As String = "Gothenburg, sweden" If (origin IsNot Nothing) AndAlso (destination IsNot Nothing) Then GoogleMap1.Directions.Add(New GoogleDirections() With { .Destination = New Location(destination), .Origin = New Location(origin), .Draggable = True, .PanelID = "route" }) End If GoogleMap1.Markers.Add(car) GoogleMap1.Markers.Add(car3) GoogleMap1.Polylines.Add(polyline) |