androidandroid-layoutandroid-2.2-froyoandroid-mapsandroid-sdk-2.1

How to get my layout correct for inputting coordinates in EditTexts for Maps


I need to input latitude and longitude separately in 2 EditTexts and display the location at the click of a button. Somehow i'm not able to get the correct layout as i precisely require 2 EditTexts aligned side by side and a button below them.

Here is what i already have:

    <LinearLayout android:id="@+id/zoom" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_centerHorizontal="true" />

    <EditText  
        android:layout_width="wrap_content" 
        android:text="@+id/EditText01"      
        android:layout_height="wrap_content" 
        android:id="@+id/edLat" 
        android:layout_toRightOf="@+id/mapView">
    </EditText>
    <EditText 
        android:layout_marginLeft="-237dip"  
        android:layout_marginTop="100dip" 
        android:layout_width="wrap_content" 
        android:text="@+id/EditText01" 
        android:layout_height="wrap_content" 
        android:id="@+id/edLong" 
        android:layout_toRightOf="@+id/mapView">
    </EditText>
    <Button 
        android:layout_marginLeft="-237dip"            
        android:layout_marginTop="200dip" 
        android:layout_width="wrap_content" 
        android:text="Show Location" 
        android:layout_height="wrap_content" 
        android:id="@+id/btnShowLoc"  
        android:layout_toRightOf="@+id/mapView"></Button>

    <com.google.android.maps.MapView 

        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:enabled="true"
        android:clickable="true"
        android:apiKey="0p8EoZESYekrClENQbOlN5EN16DgXv7Rx0CPTMg" />

</LinearLayout>

Solution

  • The below code suits your requirements:

    <LinearLayout android:id="@+id/zoom" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_alignParentBottom="true" 
            android:layout_centerHorizontal="true" 
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical">
    
        <LinearLayout android:id="@+id/LinearLayout01" 
                      android:layout_width="wrap_content" 
                      android:layout_height="wrap_content"
                      android:orientation="horizontal">
    
              <EditText 
                android:layout_width="wrap_content"     
                android:layout_height="wrap_content"    
                android:id="@+id/edLat">
              </EditText>
    
              <EditText     
                android:layout_width="wrap_content"     
                android:layout_height="wrap_content"    
                android:id="@+id/edLong">
               </EditText>
        </LinearLayout>
    
        <Button 
            android:layout_width="wrap_content" 
            android:text="Show Location" 
            android:layout_height="wrap_content" 
            android:id="@+id/btnShowLoc">
        </Button>
    
        <com.google.android.maps.MapView 
    
            android:id="@+id/mapView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:enabled="true"
            android:clickable="true"
            android:apiKey="0p8EoZESYekrClENQbOlN5EN16DgXv7Rx0CPTMg"
            />
    </LinearLayout>
    

    Note:

    you have written the below kind of code:

     <EditText android:layout_marginLeft="-237dip" android:layout_marginTop="100dip" android:layout_width="wrap_content" android:text="@+id/EditText01" android:layout_height="wrap_content" android:id="@+id/edLong" android:layout_toRightOf="@+id/mapView"></EditText>
    

    I would like to tell you that don't give this kind of position to any control because in Android, there are different types of resolutions so it will not look the same design on every Android device.

    After seeing your code, i can say you should learn Layouts and code techniques first. Refer Android-sdk pages.

    Updated Answer with Images:<29-oct-2010>


    I think you forgot to add <uses-library android:name="com.google.android.maps" /> permission in AndroidManifest.xml file, add this permission inside the <application> tag.

    Check out the below image, the same above code working for me:

    alt text