@@ -412,63 +412,44 @@ public String getPlacesAsKML(final LatLng leftLatLng, final LatLng rightLatLng)
412
412
"<!--Created by Wikimedia Commons Android app -->\n " +
413
413
"<kml xmlns=\" http://www.opengis.net/kml/2.2\" >\n " +
414
414
" <Document>" ;
415
-
416
- int increment = 1 ;
417
- double longitude = leftLatLng .getLongitude ();
418
-
419
- while (longitude <= rightLatLng .getLongitude ()) {
420
- double NEXT_LONGITUDE =
421
- (increment + longitude ) >= 0.0 && (increment + longitude ) <= 1.0 ? 0.0
422
- : increment + longitude ;
423
-
424
- double latitude = leftLatLng .getLatitude ();
425
-
426
- while (latitude <= rightLatLng .getLatitude ()) {
427
- double NEXT_LATITUDE =
428
- (increment + latitude ) >= 0.0 && (increment + latitude ) <= 1.0 ? 0.0
429
- : increment + latitude ;
430
- List <PlaceBindings > placeBindings = runQuery (new LatLng (latitude , longitude , 0 ),
431
- new LatLng (NEXT_LATITUDE , NEXT_LONGITUDE , 0 ));
432
- if (placeBindings != null ) {
433
- for (PlaceBindings item : placeBindings ) {
434
- if (item .getItem () != null && item .getLabel () != null && item .getClas () != null ) {
435
- String input = item .getLocation ().getValue ();
436
- Pattern pattern = Pattern .compile (
437
- "Point\\ (([-+]?[0-9]*\\ .?[0-9]+) ([-+]?[0-9]*\\ .?[0-9]+)\\ )" );
438
- Matcher matcher = pattern .matcher (input );
439
-
440
- if (matcher .find ()) {
441
- String longStr = matcher .group (1 );
442
- String latStr = matcher .group (2 );
443
- String itemUrl = item .getItem ().getValue ();
444
- String itemName = item .getLabel ().getValue ().replace ("&" , "&" );
445
- String itemLatitude = latStr ;
446
- String itemLongitude = longStr ;
447
- String itemClass = item .getClas ().getValue ();
448
-
449
- String formattedItemName =
450
- !itemClass .isEmpty () ? itemName + " (" + itemClass + ")"
451
- : itemName ;
452
-
453
- String kmlEntry = "\n <Placemark>\n " +
454
- " <name>" + formattedItemName + "</name>\n " +
455
- " <description>" + itemUrl + "</description>\n " +
456
- " <Point>\n " +
457
- " <coordinates>" + itemLongitude + ","
458
- + itemLatitude
459
- + "</coordinates>\n " +
460
- " </Point>\n " +
461
- " </Placemark>" ;
462
- kmlString = kmlString + kmlEntry ;
463
- } else {
464
- Timber .e ("No match found" );
465
- }
466
- }
415
+ List <PlaceBindings > placeBindings = runQuery (leftLatLng ,
416
+ rightLatLng );
417
+ if (placeBindings != null ) {
418
+ for (PlaceBindings item : placeBindings ) {
419
+ if (item .getItem () != null && item .getLabel () != null && item .getClas () != null ) {
420
+ String input = item .getLocation ().getValue ();
421
+ Pattern pattern = Pattern .compile (
422
+ "Point\\ (([-+]?[0-9]*\\ .?[0-9]+) ([-+]?[0-9]*\\ .?[0-9]+)\\ )" );
423
+ Matcher matcher = pattern .matcher (input );
424
+
425
+ if (matcher .find ()) {
426
+ String longStr = matcher .group (1 );
427
+ String latStr = matcher .group (2 );
428
+ String itemUrl = item .getItem ().getValue ();
429
+ String itemName = item .getLabel ().getValue ().replace ("&" , "&" );
430
+ String itemLatitude = latStr ;
431
+ String itemLongitude = longStr ;
432
+ String itemClass = item .getClas ().getValue ();
433
+
434
+ String formattedItemName =
435
+ !itemClass .isEmpty () ? itemName + " (" + itemClass + ")"
436
+ : itemName ;
437
+
438
+ String kmlEntry = "\n <Placemark>\n " +
439
+ " <name>" + formattedItemName + "</name>\n " +
440
+ " <description>" + itemUrl + "</description>\n " +
441
+ " <Point>\n " +
442
+ " <coordinates>" + itemLongitude + ","
443
+ + itemLatitude
444
+ + "</coordinates>\n " +
445
+ " </Point>\n " +
446
+ " </Placemark>" ;
447
+ kmlString = kmlString + kmlEntry ;
448
+ } else {
449
+ Timber .e ("No match found" );
467
450
}
468
451
}
469
- latitude += increment ;
470
452
}
471
- longitude += increment ;
472
453
}
473
454
kmlString = kmlString + "\n </Document>\n " +
474
455
"</kml>\n " ;
@@ -495,60 +476,42 @@ public String getPlacesAsGPX(final LatLng leftLatLng, final LatLng rightLatLng)
495
476
" xsi:schemaLocation=\" http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\" >"
496
477
+ "\n <bounds minlat=\" $MIN_LATITUDE\" minlon=\" $MIN_LONGITUDE\" maxlat=\" $MAX_LATITUDE\" maxlon=\" $MAX_LONGITUDE\" />" ;
497
478
498
- int increment = 1 ;
499
- double longitude = leftLatLng .getLongitude ();
500
-
501
- while (longitude <= rightLatLng .getLongitude ()) {
502
- double NEXT_LONGITUDE =
503
- (increment + longitude ) >= 0.0 && (increment + longitude ) <= 1.0 ? 0.0
504
- : increment + longitude ;
505
-
506
- double latitude = leftLatLng .getLatitude ();
507
-
508
- while (latitude <= rightLatLng .getLatitude ()) {
509
- double NEXT_LATITUDE =
510
- (increment + latitude ) >= 0.0 && (increment + latitude ) <= 1.0 ? 0.0
511
- : increment + latitude ;
512
- List <PlaceBindings > placeBindings = runQuery (new LatLng (latitude , longitude , 0 ),
513
- new LatLng (NEXT_LATITUDE , NEXT_LONGITUDE , 0 ));
514
- if (placeBindings != null ) {
515
- for (PlaceBindings item : placeBindings ) {
516
- if (item .getItem () != null && item .getLabel () != null && item .getClas () != null ) {
517
- String input = item .getLocation ().getValue ();
518
- Pattern pattern = Pattern .compile (
519
- "Point\\ (([-+]?[0-9]*\\ .?[0-9]+) ([-+]?[0-9]*\\ .?[0-9]+)\\ )" );
520
- Matcher matcher = pattern .matcher (input );
521
-
522
- if (matcher .find ()) {
523
- String longStr = matcher .group (1 );
524
- String latStr = matcher .group (2 );
525
- String itemUrl = item .getItem ().getValue ();
526
- String itemName = item .getLabel ().getValue ().replace ("&" , "&" );
527
- String itemLatitude = latStr ;
528
- String itemLongitude = longStr ;
529
- String itemClass = item .getClas ().getValue ();
530
-
531
- String formattedItemName =
532
- !itemClass .isEmpty () ? itemName + " (" + itemClass + ")"
533
- : itemName ;
534
-
535
- String gpxEntry =
536
- "\n <wpt lat=\" " + itemLatitude + "\" lon=\" " + itemLongitude
537
- + "\" >\n " +
538
- " <name>" + itemName + "</name>\n " +
539
- " <url>" + itemUrl + "</url>\n " +
540
- " </wpt>" ;
541
- gpxString = gpxString + gpxEntry ;
542
-
543
- } else {
544
- Timber .e ("No match found" );
545
- }
546
- }
479
+ List <PlaceBindings > placeBindings = runQuery (leftLatLng ,rightLatLng );
480
+ if (placeBindings != null ) {
481
+ for (PlaceBindings item : placeBindings ) {
482
+ if (item .getItem () != null && item .getLabel () != null && item .getClas () != null ) {
483
+ String input = item .getLocation ().getValue ();
484
+ Pattern pattern = Pattern .compile (
485
+ "Point\\ (([-+]?[0-9]*\\ .?[0-9]+) ([-+]?[0-9]*\\ .?[0-9]+)\\ )" );
486
+ Matcher matcher = pattern .matcher (input );
487
+
488
+ if (matcher .find ()) {
489
+ String longStr = matcher .group (1 );
490
+ String latStr = matcher .group (2 );
491
+ String itemUrl = item .getItem ().getValue ();
492
+ String itemName = item .getLabel ().getValue ().replace ("&" , "&" );
493
+ String itemLatitude = latStr ;
494
+ String itemLongitude = longStr ;
495
+ String itemClass = item .getClas ().getValue ();
496
+
497
+ String formattedItemName =
498
+ !itemClass .isEmpty () ? itemName + " (" + itemClass + ")"
499
+ : itemName ;
500
+
501
+ String gpxEntry =
502
+ "\n <wpt lat=\" " + itemLatitude + "\" lon=\" " + itemLongitude
503
+ + "\" >\n " +
504
+ " <name>" + itemName + "</name>\n " +
505
+ " <url>" + itemUrl + "</url>\n " +
506
+ " </wpt>" ;
507
+ gpxString = gpxString + gpxEntry ;
508
+
509
+ } else {
510
+ Timber .e ("No match found" );
547
511
}
548
512
}
549
- latitude += increment ;
550
513
}
551
- longitude += increment ;
514
+
552
515
}
553
516
gpxString = gpxString + "\n </gpx>" ;
554
517
return gpxString ;
0 commit comments