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'"