How to open Google Maps using address?

前端 未结 7 1031
野趣味
野趣味 2021-02-07 06:57

How can I open Google Maps(using Intents or adding Google Maps into my application) with address? I have the address, but I don\'t have latitude/longitude. How can I do it? Than

相关标签:
7条回答
  • 2021-02-07 07:00

    Change the bold part of this URL to your company address. It's best if you replace all spaces with a plus (+) character, but should work with spaces too: http://maps.google.com/maps/geo?q=620+8th+Avenue,+New+York,+NY+10018,+USA&output=csv&oe=utf8&sensor=false

    Raise a request to above URL. For more information refer http://androidadvice.blogspot.in/2010/09/asynchronous-web-request.html

    This will generate a code that looks something like this:

    200,8,40.7562008,-73.9903784
    

    The first number, 200, says that the address is good. The second number, 8, indicates how accurate the address is. The last two numbers, 40.7562008 and -73.9903784, are the latitude and longitude of this address. Use these to get your google map working.

    Note : The above steps have been copied from http://webdesign.about.com/od/javascript/ss/add-google-maps-to-a-web-page_2.htm

    0 讨论(0)
  • 2021-02-07 07:07

    Little late to the party. I prefer @st0le's answer but URLEncoder.encode(String s) is deprecated as of API 16. You need to pass a second argument as well. Check the answer below.

     public static Intent viewOnMapA(String address) {
        try {
            return new Intent(Intent.ACTION_VIEW,
                    Uri.parse(String.format("geo:0,0?q=%s",
                            URLEncoder.encode(address, "UTF-8"))));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    0 讨论(0)
  • 2021-02-07 07:13

    You can use Google Geocoding API, which converts your physical address into latitude and longitude. API returns it into XML or JSON format. You just need to parse the data to get latitude and longitude. After receiving latitude and longitude you can load it on mapview.

    Geocoding api link :

    https://developers.google.com/maps/documentation/geocoding/

    Hope this helps.

    0 讨论(0)
  • 2021-02-07 07:14
    String geoUri = "http://maps.google.com/maps?q=loc:" + addressName;
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri));
                context.startActivity(intent);
    
    0 讨论(0)
  • 2021-02-07 07:17

    As of 2017 the recommended by Google approach is using the Google Maps URLs API that provides universal cross-platform URLs. You can use these URLs in your intents.

    Example of such URL from the documentation:

    https://www.google.com/maps/search/?api=1&query=centurylink+field

    Hope this helps!

    0 讨论(0)
  • 2021-02-07 07:25

    From my personal Code Library. ;)

    public static Intent viewOnMap(String address) {
        return new Intent(Intent.ACTION_VIEW,
                          Uri.parse(String.format("geo:0,0?q=%s",
                                                  URLEncoder.encode(address))));
    }
    
    public static Intent viewOnMap(String lat, String lng) {
        return new Intent(Intent.ACTION_VIEW,
                          Uri.parse(String.format("geo:%s,%s", lat, lng)));
    }
    
    0 讨论(0)
提交回复
热议问题