How can I find the latitude and longitude from address?

前端 未结 9 1168
礼貌的吻别
礼貌的吻别 2020-11-22 10:27

I want to show the location of an address in Google Maps.

How do I get the latitude and longitude of an address using the Google Maps API?

9条回答
  •  眼角桃花
    2020-11-22 11:17

    This is how you can find the latitude and longitude of where we have click on map.

    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
        //---when user lifts his finger---
        if (event.getAction() == 1) 
        {                
            GeoPoint p = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());
    
            Toast.makeText(getBaseContext(), 
                 p.getLatitudeE6() / 1E6 + "," + 
                 p.getLongitudeE6() /1E6 , 
                 Toast.LENGTH_SHORT).show();
        }                            
        return false;
    } 
    

    it works well.

    To get the location's address we can use geocoder class.

提交回复
热议问题