My current location is not clear in Google map Android - android

I use Google map in my app. I try to get my current location I can show my location but the point is not clear. I don't Know what is problem .
As you can see picture below.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatches {
public static void main(String args[]) {
// String to be scanned to find the pattern.
String line = "This order was placed for QT3000! OK?";
String pattern = "(.*)(\\d+)(.*)";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(line);
if (m.find()) {
System.out.println("Found value: " + m.group(0));
System.out.println("Found value: " + m.group(1));
System.out.println("Found value: " + m.group(2));
} else {
System.out.println("NO MATCH");
}
}
}
Anyone know solution that ?

Your current location will not work correctly in emulator. Current location is not showing in my android app You should try it in actual device to get correct result. For focus in or out you may use this code:
mMap.addMarker(MarkerOptions().position(mylocation).title("My Location"))
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mylocation, 14f))
You can change 14f to what you want.

Related

Logcat: make output using 'Log' class show full package name

I am using statements in my code in the same class that look like:
Log.i(TAG, "Writing command to initialize the FORA");
and
Log.i(TAG, "onDescriptorWrite signaled with status " + status);
yet the output from the first one is
Writing command to initialize the FORA
but the second one is
04-11 08:01:13.109 9030-9139/? I/com.lampreynetworks.ahd.transport.btle.b: onDescriptorWrite signaled with status 0
I would like to have the output with the package name in both cases. I thought that was determined by the TAG which in my case is
private static final String TAG = AndroidBtleHandler.class.getName();
I thought it might be because some of the statements were in a class within the class but that is not so. What do I need to do to get the full package name in the logcat output?
It's not dependent on the message itself. If you have directly following info logs with Log.i() from the same class in your Logcat, only the first one shows the class name. (I don't know why that is.) It's the same with Log.w().
If you use Log.d(), the class name is shown every time.
public class App {
public static String getTag() {
String tag = "";
final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
for (int i = 0; i < ste.length; i++) {
if (ste[i].getMethodName().equals("getTag")) {
tag = "("+ste[i + 1].getFileName() + ":" + ste[i + 1].getLineNumber()+")";
}
}
return tag;
}
}
And instead of Log.i(TAG, "Writing command to initialize the FORA"); use Log.i(App.getTag(), "Writing command to initialize the FORA")

Regex with error checking

I've done a bunch of searching but I'm terrible with regex statements and my google-fu in this instance as not been strong.
Scenario:
In push notifications, we're passed a URL that contains a 9-digit content ID.
Example URL: http://www.something.com/foo/bar/Some-title-Goes-here-123456789.html (123456789 is the content ID in this scenario)
Current regex to parse the content ID:
public String getContentIdFromPathAndQueryString(String path, String queryString) {
String contentId = null;
if (StringUtils.isNonEmpty(path)) {
Pattern p = Pattern.compile("([\\d]{9})(?=.html)");
Matcher m = p.matcher(path);
if (m.find()) {
contentId = m.group();
} else if (StringUtils.isNonEmpty(queryString)) {
p = Pattern.compile("(?:contentId=)([\\d]{9})(?=.html)");
m = p.matcher(queryString);
if (m.find()) {
contentId = m.group();
}
}
}
Log.d(LOG_TAG, "Content id " + (contentId == null ? "not found" : (" found - " + contentId)));
if (StringUtils.isEmpty(contentId)) {
Answers.getInstance().logCustom(new CustomEvent("eid_url")
.putCustomAttribute("contentId", "empty")
.putCustomAttribute("path", path)
.putCustomAttribute("query", queryString));
}
return contentId;
}
The problem:
This does the job but there's a specific error scenario that I need to account for.
Whoever creates the push may put in the wrong length content ID and we need to grab it regardless of that, so assume it can be any number of digits... the title can also contain digits, which is annoying. The content ID will ALWAYS be followed by ".html"
While the basic answer here would be just "replace {9} limiting quantifier matching exactly 9 occurrences with a + quantifier matching 1+ occurrences", there are two patterns that can be improved.
The unescaped dot should be escaped in the pattern to match a literal dot.
If you have no overlapping matches, no need to use a positive lookahead with a capturing group before it, just keep the capturing group and grab .group(1) value.
A non-capturing group (?:...) is still a consuming pattern, and the (?:contentId=) equals contentId= (you may remove (?: and )).
There is no need wrapping a single atom within a character class, use \\d instead of [\\d]. That [\\d] is actually a source of misunderstandings, some may think it is a grouping construct, and might try adding alternative sequences into the square brackets, while [...] matches a single char.
So, your code can look like
Pattern p = Pattern.compile("(\\d+)\\.html"); // No lookahead, + instead of {9}
Matcher m = p.matcher(path);
if (m.find()) {
contentId = m.group(1); // (1) refers to Group 1
} else if (StringUtils.isNonEmpty(queryString)) {
p = Pattern.compile("contentId=(\\d+)\\.html");
m = p.matcher(queryString);
if (m.find()) {
contentId = m.group(1);
}
}

Search Results are in english though Search Language set to german

I am doing offline geocoding with skobbler sdk. I use the offline map for Germany and I am searching for States within Germany. I have set the search language to German. As an example I am looking for "Niedersachsen". Passing the first few letters, e.g. "Nie" makes the SearchManager find "Niedersachsen" but in the skSearchResult variable the name is "Lower Saxony". So the correct State is found but in the wrong language(english instead of german). How can I solve this? Here is my piece of codes which does the search:
public class AddressSearchListener implements SKSearchListener {
// current list level at which to search
private String mapPackageName;
private AddressSearchFragment addressSearchFragment;
public AddressSearchListener() {
Log.d("AddressSearchListener", "begin");
this.mapPackageName = "DE";
}
public void setFragment(AddressSearchFragment addressSearchFragment) {
this.addressSearchFragment = addressSearchFragment;
}
public void startSearch(long parentId, SKSearchManager.SKListLevel searchLevel, String s) {
Log.d("AddressSearchListener", "startSearch begin");
// get a search manager object
SKSearchManager mgr = new SKSearchManager(this);
// get a multi-step search object
SKMultiStepSearchSettings searchSettings = new SKMultiStepSearchSettings();
searchSettings.setSearchLanguage(SKMaps.SKLanguage.LANGUAGE_DE);
// set the offline package in which to search
// the France package in this case needs to be installed
searchSettings.setOfflinePackageCode(mapPackageName);
// set list level of the search
searchSettings.setListLevel(searchLevel);
// set maximum number of results to be received
searchSettings.setMaxSearchResultsNumber(20);
// set the id of the parent in which to search
searchSettings.setParentIndex(parentId);
// set a filter for the results
searchSettings.setSearchTerm(s);
// initiate the search
Log.d("AddressSearchListener", "startSearch time " + System.currentTimeMillis());
mgr.multistepSearch(searchSettings);
}
#Override
public void onReceivedSearchResults(List<SKSearchResult> skSearchResults) {
Log.d(getClass().getName(), "onReceivedSearchResults begin");
Log.d("AddressSearchListener", "onReceivedSearchResults time " + System.currentTimeMillis());
List<AddressSearchResultMeta> addressSearchResults = new ArrayList<AddressSearchResultMeta>();
for (SKSearchResult skSearchResult : skSearchResults) {
Log.d("onReceivedSearchResults", "result: " + skSearchResult);
AddressSearchResultMeta addressSearchResultMeta = new AddressSearchResultMeta(skSearchResult);
addressSearchResults.add(addressSearchResultMeta);
}
addressSearchFragment.passResults(addressSearchResults);
}
}
The issue was just a bug within Skobbler SDK. It is fixed in version 2.5.1.

Google Maps automatically convert period (.) into comma (,) from my Intent URI

I'm calling Google Maps Intent from my activity with this code found on StackOverflow:
final String uriContent = String.format(Locale.ENGLISH, "http://maps.google.com/maps?q=loc:%s", pCoordinate);
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriContent));
pContext.startActivity(intent);
where pCooriante contains entirely address such as 1.23456,7.8901.
It works well when my phone is using English as its language, but when I change it to French or Vietnamese (which use comma , as its number decimal seperator), it can't work anymore, because the query proceeded by Google Maps look like: 1,000,2,000 (it is shown in the search bar, and after that, a message like Cannot find 1,0000,2,0000 appears), although the exact URI I sent to the intent is 1.000,2.000 (the coordinate is converted to String to prevent Locale problems, and therefore the Locale.ENGLISH in String.format is more or less just abundant).
In short, Uri.parse(uriContent) return exactly the request with the query is 1.000,2.000, but Google Maps itself changed it. However, the code for direction works well with either Locale:
final String uriContent = String.format(Locale.ENGLISH, "google.navigation:q=%s", pCoordinate);
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriContent));
pContext.startActivity(intent);
Is there anyway to prevent the conversion of Google Maps? If I use geo:<coordinate>, it's fine, but I need a marker at that position.
Addional information:
This code final String uriContent = String.format("geo:0,0?q=%s&z=19", pCoordinate); doesn't work too, the periods are converted into commas.
This code final String uriContent = String.format("geo:%s?q=%s&z=19", pCoordinate, pCoordinate); can bring the map center to the coordinate, but still cannot put the marker there, and with the error "Cannot find 'coordinate with periods replaced by commas'"
I am using a temporary solution to this problem, by converting the decimal form of coordinates to degree one. (For example, instead of sending 10.768717,106.651488, I send 10° 46' 7.3812",106° 39' 5.3568"). The conversion is just simple mathematics operation.
However, there was a problem with Java float and double precision, and that was a lot of distance when sending to Google Maps. Therefore I change my input data, convert data using C#'s decimal and my Android app just use it without manupilating anything. Here is the convesion (C#) code:
protected String convertDecimalToDegree(decimal pDecimal)
{
int degree = (int)Math.Floor(pDecimal);
pDecimal -= degree;
pDecimal *= 60;
int minute = (int)Math.Floor(pDecimal);
pDecimal -= minute;
pDecimal *= 60;
return degree + "° " + minute + "\' " + pDecimal + "\"";
}
Usage:
String[] coordinates = shop.MapCoordination.Split(',');
decimal n1 = Decimal.Parse(coordinates[0]);
decimal n2 = Decimal.Parse(coordinates[1]);
shop.MapCoordination = this.convertDecimalToDegree(n1) + "," + this.convertDecimalToDegree(n2);
I will mark this as answer for now, but I appreciate any solution without having to convert to this form.
You can use the following snippet to solve the problem
public String getCoordinates(String coordinates){
if(Locale.FRANCE == Locale.getDefault()){
Pattern p = Pattern.compile(",.*?(,)");
Matcher m = p.matcher(coordinates);
if (m.find( )) {
int index = m.end(); //gets the second comma position
String str1 = coordinates.substring(0,index-1);
String str2 = coordinates.substring(index,coordinates.length());
NumberFormat nf = NumberFormat.getInstance(Locale.FRANCE);
try {
str1 = nf.parse(str1).toString();
str2 = nf.parse(str2).toString();
} catch (ParseException e) {
e.printStackTrace();
}
return str1+","+str2;
}
}
return coordinates;
}
Updating the Google Maps app to the latest version (7.2.0) seems to fix the issue.
in Xamarin.Android:
using System.Globalization;
Android.Net.Uri.Parse("http://maps.google.com/maps?daddr=" + myLatitude.ToString(CultureInfo.InvariantCulture) + "," + myLongitude.ToString(CultureInfo.InvariantCulture)));

Parse String with quotation marks inside

I've been trying to solve this issue for some time but still didn't find the answer. The aim is to get some data from a HTML webpage. I can do all the internet related part but i've got a problem. This is the string i have:
class="datastream-graph-value">
496
The problem are those quotation marks because otherwise my app would be able to get the "496" which is the important data, but with them there i can't get my data.
Which would be a good way to get that data? (Note that after the ">" symbol there is a "\n")
Thank you mates!
While I don't normally recommend regular expressions to read xml but HTML with an XML parser can be nightmare.
With the below sample.
<a class="datastream-graph-value" href="http=blah" > 496</a>
<a class="other"> 496</a>
Use the below regular expression it should handle it well.
(class=["][^>"]*["])
Gives a great example of how to use that regex.
http://www.vogella.com/articles/JavaRegularExpressions/article.html
If you need a code sample reply back and we will see what we can't work out.
edit:
I was bored so I thought why not put a sample together
package temp;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTestPatternMatcher {
public static final String EXAMPLE_TEST = "<a class=\"datastream-graph-value\" href=\"http=blah\" > 496</a> <a class=\"other\"> 496</a>";
public static void main(String[] args) {
Pattern pattern = Pattern.compile("(class=[\"][^>\"]*[\"])");
// In case you would like to ignore case sensitivity you could use this
// statement
// Pattern pattern = Pattern.compile("\\s+", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(EXAMPLE_TEST);
// Check all occurance
while (matcher.find()) {
System.out.print("Start index: " + matcher.start());
System.out.print(" End index: " + matcher.end() + " ");
String match = matcher.group();
match = match.replace("class=", "");
System.out.println(match);
}
// Now create a new pattern and matcher to replace whitespace with tabs
Pattern replace = Pattern.compile("\\s+");
Matcher matcher2 = replace.matcher(EXAMPLE_TEST);
System.out.println(matcher2.replaceAll("\t"));
}
}

Categories

Resources