How to open standard Google Map application from my application?

后端 未结 9 943
星月不相逢
星月不相逢 2020-11-28 01:09

Once user presses button in my application, I would like to open standard Google Map application and to show particular location. How can I do it? (without using com.g

9条回答
  •  Happy的楠姐
    2020-11-28 01:44

    Using String format will help but you must be care full with the locale. In germany float will be separates with in comma instead an point.

    Using String.format("geo:%f,%f",5.1,2.1); on locale english the result will be "geo:5.1,2.1" but with locale german you will get "geo:5,1,2,1"

    You should use the English locale to prevent this behavior.

    String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    context.startActivity(intent);
    

    To set an label to the geo point you can extend your geo uri by using:

    !!! but be carefull with this the geo-uri is still under develoment http://tools.ietf.org/html/draft-mayrhofer-geo-uri-00

    String uri = String.format(Locale.ENGLISH, "geo:%f,%f?z=%d&q=%f,%f (%s)", 
                               latitude, longitude, zoom, latitude, longitude, label);
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    context.startActivity(intent);
    

提交回复
热议问题