开发者

Android MapView coordinates x screen position

I am developing an android application which needs to handle mapview. What I basically need to do is to put right on the center of the screen a PIN, which will be over the mapview using relative layout. The user can move the map according to his will. After moving the map and positioning the PIN, I need to get the coordinated (lat and lng) from that position.

It is basically similar to the application that the user can request a cab. UberCab

The third paragraph says: "For example, as explained on the company’s blog post, when you are ordering a car you can set the pick up location by moving “the map under the stationary pin and [using] the entire map to set your location accurately. The information panels on the Android app have a clean transparency that allows you to focus on the map, and where you’re headed."

My layout will be this way:

    <RelativeLayout android:id="@+id/mapviewContainer" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:layout_below="@+id/tvCurrentAddress">   

    <ImageView android:id="@+id/pin_image_view" 
        android:layou开发者_Go百科t_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/pin_red" 
        android:layout_centerInParent="true" />  

    <com.google.android.maps.MapView android:id="@+id/mapview" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:clickable="true"            
        android:apiKey="@string/mapKey" />          

</RelativeLayout>

I would like to achieve the same thing. Does anyone know how to achieve this?

Thanks for your attention

T


You would not do with with a RelativeLayout. Pins and basically anything drawn on a MapView that is linked to geo coordinates is drawn using an Overlay or more commonly an ItemizedOverlay.

Though to answer your main question. You can convert coordinates to pixel coordinates by a system similar to this:

GeoPoint location;
-- get the location someway like through the onTap method -- 
Point screenPoint = new Point();
mapView.getProjection().toPixels(location, screenPoint);

Now screenPoint will have the pixel coordinates of the GeoPoint.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜