Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter_android] Fixes points losing precision when converting to LatLng #7101

Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.4.4

* Fixes Points losing precision when converting to LatLng
* Updates minimum Flutter version to 3.0.

## 2.4.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.model.BitmapDescriptor;
Expand Down Expand Up @@ -592,13 +593,14 @@ static String interpretCircleOptions(Object o, CircleOptionsSink sink) {
}
}

private static List<LatLng> toPoints(Object o) {
@VisibleForTesting
static List<LatLng> toPoints(Object o) {
final List<?> data = toList(o);
final List<LatLng> points = new ArrayList<>(data.size());

for (Object rawPoint : data) {
final List<?> point = toList(rawPoint);
points.add(new LatLng(toFloat(point.get(0)), toFloat(point.get(1))));
points.add(new LatLng(toDouble(point.get(0)), toDouble(point.get(1))));
}
return points;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.googlemaps;

import com.google.android.gms.maps.model.LatLng;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;

public class ConvertTest {

@Test
public void ConvertToPointsConvertsThePointsWithFullPrecision() {
double latitude = 43.03725568057;
double longitude = -87.90466904649;
ArrayList<Double> point = new ArrayList<Double>();
point.add(latitude);
point.add(longitude);
ArrayList<ArrayList<Double>> pointsList = new ArrayList<>();
pointsList.add(point);
List<LatLng> latLngs = Convert.toPoints(pointsList);
LatLng latLng = latLngs.get(0);
Assert.assertEquals(latitude, latLng.latitude, 1e-15);
Assert.assertEquals(longitude, latLng.longitude, 1e-15);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter_android
description: Android implementation of the google_maps_flutter plugin.
repository: https://github.com/flutter/plugins/tree/main/packages/google_maps_flutter/google_maps_flutter_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 2.4.3
version: 2.4.4

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down