Show location on Map - Android Hardware

Android examples for Hardware:Gps

Description

Show location on Map

Demo Code


import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Main {

  public static void locate(Context context, String chooserTilte, String lat, String lng, String addr) {
    if (null == context) {
      return;//  w  w  w.  j  a  va  2 s.  c  om
    }
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String uri = "geo:0,0" + "?q=" + lat + "," + lng;
    if (null != addr && addr.length() > 0) {
      uri += ("(" + addr + ")");
    }
    intent.setData(Uri.parse(uri));

    try {
      context.startActivity(Intent.createChooser(intent, chooserTilte).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    } catch (Exception e) {

    }
  }
}

Related Tutorials