I have a issue with my java code. i asked the same question yesterday. I got answer but sorry it was my fault. My question is not clear.
I have code looks like this:
for(i = 0; i < geo.getTargets().length ; i++ )
{
if(geo.getTargets(i).getTargetType().equalsIgnoreCase("ProximityTarget"))
{
final ProximityTarget prox = (ProximityTarget)geo.getTargets(i);
prox.getGeoPoint().getLatitudeInMicroDegrees();
prox.getGeoPoint().getLongitudeInMicroDegrees();
prox.getRadiusDistanceUnits();
}
}
The above three method will give me some values.
I want these values to be place in this format:
circle:long:lat:radius | circle:long:lat:radius | .....
Can any one help me in fixing this code. I would like these value to be concatenated in a single string in order to insert it into my database field.
Try this:
StringBuilder sb = new StringBuilder();
for(i = 0; i < geo.getTargets().length ; i++ ){
if(geo.getTargets(i).getTargetType().equalsIgnoreCase("ProximityTarget")){
final ProximityTarget prox = (ProximityTarget)geo.getTargets(i);
float longitude = prox.getGeoPoint().getLatitudeInMicroDegrees());
float lat = prox.getGeoPoint().getLongitudeInMicroDegrees());
float radius = prox.getRadiusDistanceUnits();
if (sb.isEmpty()) {
sb.append("circle:" + longitude + ":" + lat + ":" + radius);
else {
sb.append(" | circle:" + longitude + ":" + lat + ":" + radius);
}
}
}
String result = sb.toString();
This is the basic way of doing what you asked for with String + operator.
String result = "";
for(i = 0; i < geo.getTargets().length ; i++ ){
if(geo.getTargets(i).getTargetType().equalsIgnoreCase("ProximityTarget")){
final ProximityTarget prox = (ProximityTarget)geo.getTargets(i);
float longitude = prox.getGeoPoint().getLatitudeInMicroDegrees());
float lat = prox.getGeoPoint().getLongitudeInMicroDegrees());
float radius = prox.getRadiusDistanceUnits();
if (!result.isEmpty()) {
result += "|";
}
result += ("circle:" + longitude + ":" + lat + ":" + radius);
}
}
return result;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With