Skip to content

Add bounds to GoogleAddress #70

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

Merged
merged 1 commit into from
Jun 13, 2017
Merged
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
9 changes: 8 additions & 1 deletion Google/GoogleAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class GoogleAddress : Address
readonly GoogleAddressComponent[] components;
readonly bool isPartialMatch;
readonly GoogleViewport viewport;
readonly Bounds bounds;
readonly string placeId;

public GoogleAddressType Type
Expand Down Expand Up @@ -37,6 +38,11 @@ public GoogleViewport Viewport
get { return viewport; }
}

public Bounds Bounds
{
get { return bounds; }
}

public string PlaceId
{
get { return placeId; }
Expand All @@ -48,7 +54,7 @@ public GoogleAddressComponent this[GoogleAddressType type]
}

public GoogleAddress(GoogleAddressType type, string formattedAddress, GoogleAddressComponent[] components,
Location coordinates, GoogleViewport viewport, bool isPartialMatch, GoogleLocationType locationType, string placeId)
Location coordinates, GoogleViewport viewport, Bounds bounds, bool isPartialMatch, GoogleLocationType locationType, string placeId)
: base(formattedAddress, coordinates, "Google")
{
if (components == null)
Expand All @@ -58,6 +64,7 @@ public GoogleAddress(GoogleAddressType type, string formattedAddress, GoogleAddr
this.components = components;
this.isPartialMatch = isPartialMatch;
this.viewport = viewport;
this.bounds = bounds;
this.locationType = locationType;
this.placeId = placeId;
}
Expand Down
18 changes: 16 additions & 2 deletions Google/GoogleGeocoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,24 @@ private IEnumerable<GoogleAddress> ParseAddresses(XPathNodeIterator nodes)

GoogleLocationType locationType = EvaluateLocationType((string)nav.Evaluate("string(geometry/location_type)"));

bool isPartialMatch;
Bounds bounds = null;
if (nav.SelectSingleNode("geometry/bounds") != null)
{
double neBoundsLatitude = (double)nav.Evaluate("number(geometry/bounds/northeast/lat)");
double neBoundsLongitude = (double)nav.Evaluate("number(geometry/bounds/northeast/lng)");
Location neBoundsCoordinates = new Location(neBoundsLatitude, neBoundsLongitude);

double swBoundsLatitude = (double)nav.Evaluate("number(geometry/bounds/southwest/lat)");
double swBoundsLongitude = (double)nav.Evaluate("number(geometry/bounds/southwest/lng)");
Location swBoundsCoordinates = new Location(swBoundsLatitude, swBoundsLongitude);

bounds = new Bounds(swBoundsCoordinates, neBoundsCoordinates);
}

bool isPartialMatch;
bool.TryParse((string)nav.Evaluate("string(partial_match)"), out isPartialMatch);

yield return new GoogleAddress(type, formattedAddress, components, coordinates, viewport, isPartialMatch, locationType, placeId);
yield return new GoogleAddress(type, formattedAddress, components, coordinates, viewport, bounds, isPartialMatch, locationType, placeId);
}
}

Expand Down