Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working #151

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ConsoleApp1/ConsoleApp1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\GoogleMapsApi\GoogleMapsApi.csproj" />
</ItemGroup>

</Project>
142 changes: 142 additions & 0 deletions ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using System;
using GoogleMapsApi;
using GoogleMapsApi.Entities.Common;
using GoogleMapsApi.Entities.Directions.Request;
using GoogleMapsApi.Entities.Directions.Response;
using GoogleMapsApi.Entities.Geocoding.Request;
using GoogleMapsApi.Entities.Geocoding.Response;
using GoogleMapsApi.StaticMaps;
using GoogleMapsApi.StaticMaps.Entities;
using System.Collections.Generic;
using System.Linq;
using GoogleMapsApi.StaticMaps.Enums;
using GoogleMapsApi.Entities.Roads.SnapToRoad;
using GoogleMapsApi.Entities.Roads.SnapToRoad.Request;
//using GoogleMapsApi.
namespace ConsoleApp1
{



class Program
{
static string apikey = "AIzaSyDikeBAymgSWrWz-9Y7Danr2mNewZV_MwI";
static void Test()
{

var drequest = new DirectionsRequest { Origin = "285 Bedford Ave, Brooklyn, NY, USA", Destination = "185 Broadway Ave, Manhattan, NY, USA" };
drequest.ApiKey = apikey;
var result = GoogleMaps.Directions.QueryAsync(drequest);
var locs = result.Result.Routes.FirstOrDefault().OverviewPath.Points;


StaticMapRequest request = new(
new AddressLocation("Brooklyn Bridge,New York,NY"), 12, new ImageSize(1024, 800))
{
MapType = MapType.Roadmap,
Scale = 1,
Pathes = new List<Path>()
{
new Path()
{
Locations = new List<ILocationString>(locs),
Style = new PathStyle()
{
Color = "blue",
Weight = 10

}

}
}
};
string expectedResult = "http://maps.google.com/maps/api/staticmap" +
"?center=Brooklyn%20Bridge%2CNew%20York%2CNY&zoom=14&size=512x512&maptype=roadmap" +
"&markers=color%3Ablue%7Clabel%3AS%7C40.702147%2C-74.015794&markers=color%3Agreen%7Clabel%3AG%7C40.711614%2C-74.012318" +
"&markers=color%3Ared%7Clabel%3AC%7C40.718217%2C-73.998284";
request.ApiKey = apikey;
string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request);
Console.WriteLine(generateStaticMapURL);
}
static void Test2()
{
RouteMapRequest routeMapRequest = new RouteMapRequest(new AddressLocation("Odesa oblast"), new ImageSize(800, 400), "Odesa", "Serhiivka")
{ Scale = 2};
routeMapRequest.CalculateZoom = true;
routeMapRequest.ApiKey = apikey;
routeMapRequest.CalculateZoom = true;
var result = new RouteMapsEngine().GenerateRouteMapURL(routeMapRequest);
Console.WriteLine(result);
}
static async void Test3()
{

var res = await GoogleMaps.SnapToRoads.QueryAsync(new SnapToRoadRequest()
{
ApiKey = apikey,
IsSSL = true,
Path = new List<ILocationString>()
{

new Location(-35.27801,149.12958),
new Location(-35.28032,149.12907),
new Location(60.170877, 24.942796),


}

});
Console.WriteLine(res);

//var res = await GoogleMaps.SnapToRoads.QueryAsync(new SnapToRoadRequest() { ApiKey = apikey, Keyword = "place", Location=new Location(60.170880, 24.942795),Radius=10 });
}
static async void Test4()
{
var res = await GoogleMaps.NearestRoads.QueryAsync(new NearestRoadsRequest()
{
ApiKey = apikey,
IsSSL = true,
Points = new List<ILocationString>()
{
new Location(60.170880,24.942795),
new Location(60.170879,24.942796),
new Location(60.170877,24.942796),
}
});
Console.WriteLine(res);
}
static async void Test5()
{
var res = new RouteMapsEngine().GenerateRouteMapURLSnap(new RouteMapRequest(new AddressLocation("Odesa"), new ImageSize(800, 400), "Odesa", "Chornomorsk")
{
ApiKey = apikey,
CalculateZoom=true,
Scale=4
});
Console.WriteLine(res);
}
static void Main(string[] args)
{
//Test();
//Test2();

//Test3();

//Test4();
Test5();
/*
var list = LocationInterpolator.GetList(
new GoogleMapsApi.Entities.Roads.Location(46.456382, 30.721864),
new GoogleMapsApi.Entities.Roads.Location(50.376512, 30.502683)
);

foreach(var l in list)
{
Console.WriteLine(l);
}
//Console.WriteLine(res);
*/
Console.ReadLine();
}
}
}
6 changes: 4 additions & 2 deletions GoogleMapsApi.Test/GoogleMapsApi.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;</TargetFrameworks>
<LangVersion>latest</LangVersion>
<TargetFrameworks>net5.0;</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<OutputType>Library</OutputType>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="AutoCompleteTextBox" Version="1.5.0" />
<PackageReference Include="MaterialDesignExtensions" Version="3.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion GoogleMapsApi.Test/IntegrationTests/BaseTestIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public BaseTestIntegration()
.Build();
}

protected string ApiKey => Configuration.GetValue<string>("GOOGLE_API_KEY");
protected string ApiKey => Configuration.GetValue<string>("AIzaSyDikeBAymgSWrWz-9Y7Danr2mNewZV_MwI");
}
}
6 changes: 5 additions & 1 deletion GoogleMapsApi.Test/IntegrationTests/DirectionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NUnit.Framework;
using GoogleMapsApi.Test.Utils;
using System.Threading.Tasks;
using GoogleMapsApi.StaticMaps;

namespace GoogleMapsApi.Test.IntegrationTests
{
Expand All @@ -17,12 +18,15 @@ public class DirectionsTests : BaseTestIntegration
public async Task Directions_SumOfStepDistancesCorrect()
{
var request = new DirectionsRequest { Origin = "285 Bedford Ave, Brooklyn, NY, USA", Destination = "185 Broadway Ave, Manhattan, NY, USA" };
request.ApiKey = ApiKey;
request.ApiKey = "AIzaSyDikeBAymgSWrWz-9Y7Danr2mNewZV_MwI";
var result = await GoogleMaps.Directions.QueryAsync(request);

//var map = new StaticMapsEngine().GenerateStaticMapURL(request);
AssertInconclusive.NotExceedQuota(result);

Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage);
Assert.Greater(result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), 100);

}

[Test]
Expand Down
55 changes: 35 additions & 20 deletions GoogleMapsApi.Test/StaticMaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,48 @@ public void BasicTest()
// downtown New York City
StaticMapRequest request = new(
new AddressLocation("Brooklyn Bridge,New York,NY"), 14, new ImageSize(512, 512))
{
MapType = MapType.Roadmap,
Markers =
new List<Marker>
{
MapType = MapType.Roadmap,
/*Markers =
new List<Marker>
{
new Marker
{
Style = new MarkerStyle { Color = "blue", Label = "S" },
Locations = new List<ILocationString> { new Location(40.702147, -74.015794) }
},
new Marker
{
Style = new MarkerStyle { Color = "green", Label = "G" },
Locations = new List<ILocationString> { new Location(40.711614, -74.012318) }
},
new Marker
{
Style = new MarkerStyle { Color = "red", Label = "C" },
Locations = new List<ILocationString> { new Location(40.718217, -73.998284) }
}
}
*/
Pathes = new List<Path>()
{
new Path()
{
Locations = new List<ILocationString> { new Location(40.711614, -74.012318), new Location(40.718217, -73.998284)},
Style = new PathStyle()
{
new Marker
{
Style = new MarkerStyle { Color = "blue", Label = "S" },
Locations = new List<ILocationString> { new Location(40.702147, -74.015794) }
},
new Marker
{
Style = new MarkerStyle { Color = "green", Label = "G" },
Locations = new List<ILocationString> { new Location(40.711614, -74.012318) }
},
new Marker
{
Style = new MarkerStyle { Color = "red", Label = "C" },
Locations = new List<ILocationString> { new Location(40.718217, -73.998284) }
}
Color = "blue",
Weight = 10

}

}
}
};
string expectedResult = "http://maps.google.com/maps/api/staticmap" +
"?center=Brooklyn%20Bridge%2CNew%20York%2CNY&zoom=14&size=512x512&maptype=roadmap" +
"&markers=color%3Ablue%7Clabel%3AS%7C40.702147%2C-74.015794&markers=color%3Agreen%7Clabel%3AG%7C40.711614%2C-74.012318" +
"&markers=color%3Ared%7Clabel%3AC%7C40.718217%2C-73.998284";

request.ApiKey = "AIzaSyDikeBAymgSWrWz-9Y7Danr2mNewZV_MwI";
string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request);

Assert.AreEqual(expectedResult, generateStaticMapURL);
Expand Down
32 changes: 30 additions & 2 deletions GoogleMapsApi.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31808.319
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GoogleMapsApi.Test", "GoogleMapsApi.Test\GoogleMapsApi.Test.csproj", "{AD9AD8E9-0E2C-470E-9004-373679F9D954}"
EndProject
Expand All @@ -17,6 +17,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "artifacts", "artifacts", "{
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GoogleMapsApi", "GoogleMapsApi\GoogleMapsApi.csproj", "{61E9FC82-47B0-43C3-8749-95D3A9967060}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UI", "google-maps-api\UI.csproj", "{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -50,6 +54,30 @@ Global
{61E9FC82-47B0-43C3-8749-95D3A9967060}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{61E9FC82-47B0-43C3-8749-95D3A9967060}.Release|x86.ActiveCfg = Release|Any CPU
{61E9FC82-47B0-43C3-8749-95D3A9967060}.Release|x86.Build.0 = Release|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Debug|x86.ActiveCfg = Debug|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Debug|x86.Build.0 = Debug|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Release|Any CPU.Build.0 = Release|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Release|x86.ActiveCfg = Release|Any CPU
{C2FD166C-D375-4C75-A0BB-1C26FEAA0F65}.Release|x86.Build.0 = Release|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Debug|x86.ActiveCfg = Debug|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Debug|x86.Build.0 = Debug|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Release|Any CPU.Build.0 = Release|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Release|x86.ActiveCfg = Release|Any CPU
{8E3B3E61-EEA4-45A9-A1AF-B584CDCEC566}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
28 changes: 28 additions & 0 deletions GoogleMapsApi/DistanceCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoogleMapsApi
{
class DistanceCalculator
{
public static double DistanceTo(double lat1, double lon1, double lat2, double lon2)
{
double rlat1 = Math.PI * lat1 / 180;
double rlat2 = Math.PI * lat2 / 180;
double theta = lon1 - lon2;
double rtheta = Math.PI * theta / 180;
double dist =
Math.Sin(rlat1) * Math.Sin(rlat2) + Math.Cos(rlat1) *
Math.Cos(rlat2) * Math.Cos(rtheta);
dist = Math.Acos(dist);
dist = dist * 180 / Math.PI;
dist = dist * 60 * 1.1515;


return dist * 1.609344;
}
}
}
13 changes: 13 additions & 0 deletions GoogleMapsApi/Entities/Common/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ public class Location : ILocationString
[DataMember(Name = "lng")]
public double Longitude { get; set; }

[DataMember(Name ="longitude")]
public double LongitudeAlternate
{
get { return Longitude; }
set { Longitude = value; }
}
[DataMember(Name = "latitude")]
public double LatitudeAlternate
{
get { return Latitude; }
set { Latitude = value; }
}

public Location(double lat, double lng)
{
Latitude = lat;
Expand Down
Loading