OSMdroid bounds marker - osmdroid

////OSMdroid centered on the markers////
I add markers, I need to map the maximum increases or decreases in such a way that all markers were visible
my code:
public class mapcode extends Activity {
globalvar appState;
int stats=0;
private MapView mapView;
private IMapController mapController;
private SimpleLocationOverlay mMyLocationOverlay;
private ScaleBarOverlay mScaleBarOverlay;
ItemizedIconOverlay<OverlayItem> currentLocationOverlay;
DefaultResourceProxyImpl resourceProxy;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.map);
appState = ((globalvar) getApplicationContext());
mapView = (MapView) this.findViewById(R.id.mapview);
mapView.setTileSource(TileSourceFactory.MAPNIK);
// mapView.setBuiltInZoomControls(true); //кнопка ZOOM +-
mapView.setMultiTouchControls(true);
mapController = this.mapView.getController();
mapController.setZoom(2);
this.mMyLocationOverlay = new SimpleLocationOverlay(this);
this.mapView.getOverlays().add(mMyLocationOverlay);
this.mScaleBarOverlay = new ScaleBarOverlay(this);
this.mapView.getOverlays().add(mScaleBarOverlay);
// this.mapView
/////////////////
resourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
GeoPoint currentLocation = new GeoPoint(55.860863,37.115046);
GeoPoint currentLocation2 = new GeoPoint(63.557413,-156.102119);
OverlayItem myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation);
Drawable myCurrentLocationMarker = this.getResources().getDrawable(R.drawable.a);
myLocationOverlayItem.setMarker(myCurrentLocationMarker);
// myLocationOverlayItem.setMarkerHotspot(HotspotPlace.CENTER); //no working/
final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
items.add(myLocationOverlayItem);
myLocationOverlayItem = new OverlayItem("Here", "Current Position", currentLocation2);
myCurrentLocationMarker = this.getResources().getDrawable(R.drawable.a);
myLocationOverlayItem.setMarker(myCurrentLocationMarker);
// myLocationOverlayItem.setMarkerHotspot(HotspotPlace.CENTER); // no working
items.add(myLocationOverlayItem);
currentLocationOverlay = new ItemizedIconOverlay<OverlayItem>(items,
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
return true;
}
public boolean onItemLongPress(final int index, final OverlayItem item) {
return true;
}
}, resourceProxy);
this.mapView.getOverlays().add(this.currentLocationOverlay);
}
I added two markers, but only one is visible:
and I need to osmdroid is centered and immediately showed both marker

I think you want something like this:
int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLong = Integer.MAX_VALUE;
int maxLong = Integer.MIN_VALUE;
ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
for (OverlayItem item : items) {
GeoPoint point = item.getPoint();
if (point.getLatitudeE6() < minLat)
minLat = point.getLatitudeE6();
if (point.getLatitudeE6() > maxLat)
maxLat = point.getLatitudeE6();
if (point.getLongitudeE6() < minLong)
minLong = point.getLongitudeE6();
if (point.getLongitudeE6() > maxLong)
maxLong = point.getLongitudeE6();
}
BoundingBoxE6 boundingBox = new BoundingBoxE6(maxLat, maxLong, minLat, minLong);
mMapView.zoomToBoundingBox(boundingBox);

You can calculate boundingBox by BoundingBox.fromGeoPoints(geoPoints)
fun zoomToBounds(points: List<LatLng>) {
val geoPoints = points.map { GeoPoint(it.latitude, it.longitude) }
val boundingBox = BoundingBox.fromGeoPoints(geoPoints)
mapView.zoomToBoundingBox(boundingBox, true)
}
It is also possible to have some paddings by using zoomtoBoundingBox overloaded method and setting the pBorderSizeInPixels parameter
public double zoomToBoundingBox(
final BoundingBox pBoundingBox,
final boolean pAnimated,
final int pBorderSizeInPixels,
final double pMaximumZoom,
final Long pAnimationSpeed
)

Related

How do i perform operations on a structures field?

I im currently having an issue with when performing an operation with my structure.
On form load, I am loading a comma delimited file with 6 indexes then using a 2d array i display the structured list's field to a grid view cell.
In the last for loop, perform the operation using my total field?
{
public partial class Form1 : Form
{
public struct Costomers
{
public string firstN;
public string lastN;
public string address;
public string item;
public double price;
public int quantity;
public double total;
}
public Form1()
{
InitializeComponent();
}
List<Costomers> consumers = new List<Costomers>();
private void Form1_Load(object sender, EventArgs e)
{
var inputfile = File.ReadAllLines("customers.txt");
for (int i = 0; i < inputfile.Length; i++)
{
var SplitArr = inputfile[i].Split(',');
// next declare a new instace of costomers
Costomers ConsumerInfo = new Costomers();
// the ConsumerInfo object now contains all of the fields i declared in the structer.
// next i want to access the Objects fields and assign them
ConsumerInfo.firstN = SplitArr[0];
ConsumerInfo.lastN = SplitArr[1];
ConsumerInfo.address = SplitArr[2];
ConsumerInfo.item = SplitArr[3];
ConsumerInfo.price = Convert.ToDouble(SplitArr[4]);
ConsumerInfo.quantity = Convert.ToInt32(SplitArr[5]);
//ConsumerInfo.total = consumers[i].price * consumers[i].quantity;
consumers.Add(ConsumerInfo);
}
// Next i need to disply each field in the grid view
// i will resue my code from section F to do this.
for (int i = 0; i < consumers.Count; i++)
{
dgInfo.Rows.Add();
dgInfo[0, i].Value = consumers[i].firstN;
dgInfo[1, i].Value = consumers[i].lastN;
dgInfo[2, i].Value = consumers[i].address;
dgInfo[3, i].Value = consumers[i].item;
dgInfo[4, i].Value = consumers[i].price;
dgInfo[5, i].Value = consumers[i].quantity;
}
// next in a seperat for loop i need too mutiply the price by the quantity
for (int i = 0; i < consumers.Count; i++)
{
Costomers totalPrice = new Costomers();
totalPrice.total = consumers[i].price * consumers[i].quantity;
dgInfo[6,i].Value = totalPrice.total;
}
}
}
}```
Second, because the file i load does not contain a index for total; how to i display the total in its own column?
Text file as shown below:
The, Batman, 123 Gotham Drive, bat belt, 193.82,17
The, Joker, 12432 Joker Way, Bat Spray, 19.99, 1022
Cat, Women, 8787 Meow St., Kibbles, 9.99, 4700
The, Penguin, 17 Waddel Ave., pointy cigarettes, 24.99, 51700
sidekick, Robin, 123 Gotham Drive, junior bat belt, 67.80, 10000
Adam, West, 1782 Hollywood Dr., hasbeen kit, 10305018.18, 1

Unknown reason for "ArgumentOutOfRangeException: Argument is out of range. Parameter name: index" exception

I am making a Unity game where the player is collecting data about aliens.
Therefor the player points on the alien and uses something like a camera.
Camera --> shoots Ray --> Ray returns all needed data attached to the script on the alien-gameobject
void ShootRay()
{
RaycastHit hitInfo; // stores information about hitted object
if (Physics.Raycast (transform.position, transform.forward, out hitInfo, maxRaycastRange, 1 << LayerMask.NameToLayer("creature"))) // out hitInfo = Unity puts information in the variable hitInfo
{
// UI alerts and collecting dna
if (hitInfo.distance <= photoRaycastRange)
{
distanceInfo.text = "scanning_genome";
if (hitInfo.collider.gameObject.GetComponent<EnemyAI> ().dna_collected == false) {
if (dna_percent_0_to_1 < 1)
{
calming_dna_scan_circle = false;
distanceInfo.text = "scanning_genome";
dna_percent_0_to_1 += Time.deltaTime * dna_scanSpeed;
dna_collect_circle.fillAmount = dna_percent_0_to_1;
}
else if (dna_percent_0_to_1 >= 1)
{
// adding info of creature to database
if (hitInfo.collider.gameObject.GetComponent<EnemyAI> ().raceIndex == 1)
{
if (!raceOneWasAdded)
{
BestiariumData.scannedSpecies.Add (hitInfo.collider.gameObject);
raceOneWasAdded = true;
}
BestiariumData.dnaBar_1 += 0.25f;
The mentioned database is simply a class called BestiariumData with:
public static List<GameObject> scannedSpecies = new List<GameObject> ();
public static List<float> savedDNAFillRates = new List<float> ();
public static float dnaBar_1 = 0;
public static float dnaBar_2 = 0;
public static float dnaBar_3 = 0;
public static float dnaBar_4 = 0;
public static float dnaBar_5 = 0;
public static float dnaBar_6 = 0;
public static float dnaBar_7 = 0;
public static float dnaBar_8 = 0;
}
I'm having a menu where the player can check which aliens he/she already has collected data. The name of the alien is displayed (Monster One, ...) and a progress bar for how many alien individuals the player has scanned.
THE PROBLEM:
if I try to assign the NAME of the status bar if throws the ArgumentOutOfRangeException: Argument is out of range. Parameter name: index exception. I am doing this by setting a bool in another script to true.
public List<GameObject> monsterButtons = new List<GameObject>();
public static bool nameButtons = false;
// Update is called once per frame
void LateUpdate ()
{
if (nameButtons)
{
for (int buttonIndex = monsterButtons.Count; buttonIndex > 0; buttonIndex--)
{
monsterButtons [buttonIndex].GetComponentInChildren<Text> ().text = BestiariumData.scannedSpecies [buttonIndex].name;
}
}
}
Thank you for your help.
Button index gives the count of your list. So say your list contains 10 items, count will be 10.
However a list's index starts at 0, not 1.
So when you try to access monsterButtons [buttonIndex] for the first time, you are calling index 10, which means item 11. This does not exist so throws your error.
To fix, add "-1" to your index asigning:
for (int buttonIndex = monsterButtons.Count -1; buttonIndex >= 0; buttonIndex--)
{
monsterButtons [buttonIndex].GetComponentInChildren<Text> ().text = BestiariumData.scannedSpecies [buttonIndex].name;
}

LEVENSHTEIN_DISTANCE doesn't ignore order by comparing of lists

P.P.S. Ok, I founded hier Javers Comparing Lists following comment
There is no concept of move in JaVers list comparison algorithms. After a move there will be two changes reported: ValueAdded and ValueRemoved, just like you have mentioned.
But how then I can recognize, that the list actually has not been changed?
P.S. Even if I get #Entities and #Id to ZasFish, ZasCatchZone and ZasCatchArea I still get
Diff:
1. NewObject{globalId:'my.javers.comparator.ZasFish/2'}
2. ObjectRemoved{globalId:'my.javers.comparator.ZasFish/1'}
I'm trying to compare lists of custom objects. I set LEVENSHTEIN_DISTANCE and created custom comparators. The only difference between objects is the order of values in the lists. I would expect "no changes", but I got ListChange. The result and example is below. What am I doing wrong?
Many thanks and regards,
Andrej
Diff:
1. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'zones', containerChanges:[(2).'my.javers.comparator.ZasCatchZone#7a9273a8'>>'my.javers.comparator.ZasCatchZone#26a7b76d', (1).'my.javers.comparator.ZasCatchZone#4abdb505'>>'my.javers.comparator.ZasCatchZone#7ce6a65d', (0).'my.javers.comparator.ZasCatchZone#1500955a'>>'my.javers.comparator.ZasCatchZone#e874448']}
2. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'areas', containerChanges:[(2).'my.javers.comparator.ZasCatchArea#7113b13f'>>'my.javers.comparator.ZasCatchArea#45820e51', (1).'my.javers.comparator.ZasCatchArea#42d8062c'>>'my.javers.comparator.ZasCatchArea#6043cd28', (0).'my.javers.comparator.ZasCatchArea#cb51256'>>'my.javers.comparator.ZasCatchArea#59906517']}
package my.javers.comparator;
public class ZasCatchArea {
String catchArea;
public String getCatchArea() {
return catchArea;
}
public void setCatchArea(String catchArea) {
this.catchArea = catchArea;
}
}
public class ZasCatchZone {
String catchZone;
public String getCatchZone() {
return catchZone;
}
public void setCatchZone(String catchZone) {
this.catchZone = catchZone;
}
}
public class ZasFish {
String fischName;
List<ZasCatchZone> zones = new ArrayList<ZasCatchZone>();
List<ZasCatchArea> areas = new ArrayList<ZasCatchArea>();
public String getFischName() {
return fischName;
}
public void setFischName(String fischName) {
this.fischName = fischName;
}
public List<ZasCatchZone> getZones() {
return zones;
}
public void setZones(List<ZasCatchZone> zones) {
this.zones = zones;
}
public List<ZasCatchArea> getAreas() {
return areas;
}
public void setAreas(List<ZasCatchArea> areas) {
this.areas = areas;
}
}
public class ZasCatchAreaComparator implements
CustomPropertyComparator<ZasCatchArea, ValueChange> {
public ValueChange compare(ZasCatchArea left, ZasCatchArea right,
GlobalId affectedCdoId, Property propertyName) {
if (left.getCatchArea().equals(right.getCatchArea()))
return null;
return new ValueChange(affectedCdoId, propertyName.getName(), left, right);
}
}
public class ZasCatchZoneComparator implements
CustomPropertyComparator<ZasCatchZone, ValueChange> {
public ValueChange compare(ZasCatchZone left, ZasCatchZone right,
GlobalId affectedCdoId, Property propertyName) {
if (left.getCatchZone().equals(right.getCatchZone()))
return null;
return new ValueChange(affectedCdoId, propertyName.getName(), left, right);
}
}
public class MyComparator {
public static void main(String[] args) {
Javers javers = JaversBuilder.javers()
.registerCustomComparator(new ZasCatchAreaComparator(), ZasCatchArea.class)
.registerCustomComparator(new ZasCatchZoneComparator(), ZasCatchZone.class)
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).build();
ZasFish fisch1 = new ZasFish();
ZasFish fisch2 = new ZasFish();
ZasCatchZone z1 = new ZasCatchZone();
z1.setCatchZone("zone1");
ZasCatchZone z2 = new ZasCatchZone();
z2.setCatchZone("zone2");
ZasCatchZone z3 = new ZasCatchZone();
z3.setCatchZone("zone3");
fisch1.getZones().add(z1);
fisch1.getZones().add(z2);
fisch1.getZones().add(z3);
ZasCatchArea a1 = new ZasCatchArea();
a1.setCatchArea("area1");
ZasCatchArea a2 = new ZasCatchArea();
a2.setCatchArea("area2");
ZasCatchArea a3 = new ZasCatchArea();
a3.setCatchArea("area3");
fisch1.getAreas().add(a1);
fisch1.getAreas().add(a2);
fisch1.getAreas().add(a3);
ZasCatchZone z4 = new ZasCatchZone();
z4.setCatchZone("zone3");
ZasCatchZone z5 = new ZasCatchZone();
z5.setCatchZone("zone2");
ZasCatchZone z6 = new ZasCatchZone();
z6.setCatchZone("zone1");
fisch2.getZones().add(z4);
fisch2.getZones().add(z5);
fisch2.getZones().add(z6);
ZasCatchArea a4 = new ZasCatchArea();
a4.setCatchArea("area3");
ZasCatchArea a5 = new ZasCatchArea();
a5.setCatchArea("area1");
ZasCatchArea a6 = new ZasCatchArea();
a6.setCatchArea("area2");
fisch2.getAreas().add(a4);
fisch2.getAreas().add(a5);
fisch2.getAreas().add(a6);
Diff diff = javers.compare(fisch1, fisch2);
System.out.println(diff);
}
}
I think I founded a solution for my issue. If I register values and value objects like this
final Javers javers = JaversBuilder.javers()
.registerCustomComparator(new ZasCatchAreaComparator(), ZasCatchArea.class)
.registerCustomComparator(new ZasCatchZoneComparator(), ZasCatchZone.class)
.registerValue(ZasCatchArea.class).registerValue(ZasCatchZone.class).registerValueObject(ZasFish.class)
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).build();
Then I get as diff
1. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'zones', containerChanges:[(2).'my.javers.comparator.ZasCatchZone#19bef4e5'>>'my.javers.comparator.ZasCatchZone#3f1abed', (1).'my.javers.comparator.ZasCatchZone#e37f307f'>>'my.javers.comparator.ZasCatchZone#2ad1e8a5', (0).'my.javers.comparator.ZasCatchZone#2ccd3209'>>'my.javers.comparator.ZasCatchZone#c0fd1f30']}
2. ListChange{globalId:'my.javers.comparator.ZasFish/', property:'areas', containerChanges:[(2).'my.javers.comparator.ZasCatchArea#48115f4e'>>'my.javers.comparator.ZasCatchArea#a1efa37', (1).'my.javers.comparator.ZasCatchArea#c08d9768'>>'my.javers.comparator.ZasCatchArea#d65a5a2', (0).'my.javers.comparator.ZasCatchArea#bb03583'>>'my.javers.comparator.ZasCatchArea#1ebaaab0']}
And as I don't have any ValueChange in this case I can ignore ListChange -> my Lists are identical.

List and Map in java programing

I need to convert:
List<Map>([{1,2},{2,3}])
To:
List<List>([[1,2],[2,3]])
Can anyone help me with example for this ...
Thanks
I would suggest making a list of specific objects instead of a raw list that the get(0) returns the key and get(1) the value as follows:
List<List<Pair>> convert(List<Map<Integer,Integer> mapList){
List<List<Pair>> listOfList = new ArrayList<List<Pair>>();
for(Map<Integer,Integer> map:mapList){
List<Pair> list = new ArrayList<Pair>();
for(Entry<Integer,Integer> e:map.entrySet()){
list.add(Pair(e.getKey(),e.getValue());
}
listOfList.add(list);
}
return listOfList;
}
class Pair{
Integer first;
Integer second;
//constructor
}
You can try the following Code:
import java.util.*;
class ListOfMapToListOfList
{
public static List<List> toList(List<Map<Integer,Integer>> lList)//method to convert List<Map> to List<List>
{
List<List> list = new ArrayList<List>();
for (int i = 0 ; i < lList.size() ; i++)
{
Map<Integer,Integer> map = lList.get(i);
List<Integer> aList = new ArrayList<Integer>();
Set<Integer> keySet = map.keySet();
for (Integer key : keySet)
{
aList.add(key);
aList.add(map.get(key));
}
list.add(aList);
}
return list;
}
public static void main(String[] args) //main body
{
List<Map<Integer,Integer>> list1 = new ArrayList<Map<Integer,Integer>>();
Map<Integer,Integer> map1 = new HashMap<Integer,Integer>();
map1.put(1,2);
Map<Integer,Integer> map2 = new HashMap<Integer,Integer>();
map2.put(1,2);
list1.add(map1);list1.add(map2);
System.out.println(list1);
System.out.println(toList(list1));//Conversion is done here..and out put is shown.
}
}

not sure how to cast convert value java7

I haven't used java since version 4 and casting seams to have changed to the point where it's almost annoying. I don't understand how to approach the following compile error.
HelloWorld.java:70: error: no suitable method found for
add(Series)
lineChart.getData().add(series);
^
method List.add(int,Series) is not applicable
(actual and formal argument lists differ in length)
method List.add(Series) is not applicable
(actual argument Series cannot be converted to Series by method invocation conversion)
Here is my code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.*;
import javafx.stage.Stage;
import javafx.geometry.Side;
import java.lang.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class HelloWorld extends Application {
#Override public void start(Stage stage) {
Vector <String[]> v = new Vector<String[]>();
try{
File f = new File("audjpy.txt");
BufferedReader br = new BufferedReader(new FileReader(f));
String line;
String[] data;
int count = 0;
while ((line = br.readLine()) != null) {
data = line.split(",");
if(count>0)v.add(data);
if(count == 400)break;
count++;
}
br.close();
}catch(IOException e){System.out.println(e);}
stage.setTitle("Line Chart Sample");
//defining the axes
NumberAxis xAxis = new NumberAxis();
NumberAxis yAxis = new NumberAxis();
yAxis.setSide(Side.RIGHT);
xAxis.setLabel("Number of Month");
//creating the chart
final LineChart<Number,Number> lineChart =
new LineChart<Number,Number>(xAxis,yAxis);
lineChart.setTitle("Stock Monitoring, 2010");
//defining a series
XYChart.Series<Double, Double> series = new XYChart.Series<Double, Double>();
series.setName("My portfolio");
//populating the series with data
//<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>
Enumeration<String[]> e = v.elements();
while(e.hasMoreElements()){
String[] data = e.nextElement();
double x = Double.parseDouble(data[4]);
double y = Double.parseDouble(data[5]);
series.getData().add(new XYChart.Data<Double, Double>(x,y));
}
Scene scene = new Scene(lineChart,800,600);
lineChart.getData().add(1, series);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The reasons seems like it is because you are using Double and Number interchangeable, change every generic to Number and your problem should be solved.
#Override
public void start(Stage stage) {
Vector<String[]> v = new Vector<String[]>();
try {
File f = new File("audjpy.txt");
BufferedReader br = new BufferedReader(new FileReader(f));
String line;
String[] data;
int count = 0;
while ((line = br.readLine()) != null) {
data = line.split(",");
if (count > 0) {
v.add(data);
}
if (count == 400) {
break;
}
count++;
}
br.close();
} catch (IOException e) {
System.out.println(e);
}
stage.setTitle("Line Chart Sample");
//defining the axes
NumberAxis xAxis = new NumberAxis();
NumberAxis yAxis = new NumberAxis();
yAxis.setSide(Side.RIGHT);
xAxis.setLabel("Number of Month");
//creating the chart
final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
lineChart.setTitle("Stock Monitoring, 2010");
//defining a series
XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
series.setName("My portfolio");
//populating the series with data
//<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>
Enumeration<String[]> e = v.elements();
while (e.hasMoreElements()) {
String[] data = e.nextElement();
double x = Double.parseDouble(data[4]);
double y = Double.parseDouble(data[5]);
series.getData().add(new XYChart.Data<Number, Number>(x,y));
}
Scene scene = new Scene(lineChart, 800, 600);
lineChart.getData().add(1, series);
stage.setScene(scene);
stage.show();
}