How to insert locations marked on maps in a dynamic listview

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

How to insert locations marked on maps in a dynamic listview

Postby spoortigandhad » Mon Apr 11, 2011 6:54 am

Hi all,

I'm developing an android Travel app. I'm able to mark the nearest places on map. It will be helpfull if i get to know how to make a dynamic listView of all the places marked on the map.

Thank you.
spoortigandhad
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Apr 11, 2011 6:28 am

Top

Re: How to insert locations marked on maps in a dynamic list

Postby Openxcell » Mon Apr 11, 2011 8:27 am

spoortigandhad wrote:Hi all,

I'm developing an android Travel app. I'm able to mark the nearest places on map. It will be helpfull if i get to know how to make a dynamic listView of all the places marked on the map.

Thank you.


First of all fetch values from maps store it in some variables for further use. Then you can pass that value in list view code to add in list view. Code for list view is mentioned here.

Step 1 - Create a Listview

Create a simple listview with a LayoutTemplate and ItemTemplate to display your data. Here is some sample code you can use:

<asp:ListView ID="Listview2" runat="server" DataKeyNames="ID"
DataSourceID="dsListView" InsertItemPosition="LastItem">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0" class="ListviewTable" width="540">
<tr>
<th style="width: 40px">
ID
</th>
<th style="width: 110px">
First Name
</th>
<th style="width: 110px">
Last Name
</th>
<th style="width: 120px">
Department
</th>
<th style="width: 120px">
Location
</th>
<th style="width: 40px">
</th>
</tr>
<tr id="itemPlaceholder" runat="server" />
<tr>
<td colspan="5" align="center">
Page:
<asp:DataPager ID="DataPager1" runat="server" PageSize="12">
<Fields>
<asp:NumericPagerField ButtonCount="5" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%#Eval("ID")%>
</td>
<td>
<%#Eval("FirstName")%>
</td>
<td>
<%#Eval("LastName")%>
</td>
<td>
<%#Eval("Location")%>
</td>
<td>
<%#Eval("Department")%>
</td>
<td>

</td>
</tr>
</ItemTemplate>
</asp:ListView>

In the Listview control you'll see InsertItemPosition="LastItem" which puts the insert item template into the Listview's footer. You can use FirstItem to show the insert item template at the top of your data.



Step 2 - Create the SQL Data Source

My usual disclaimer here - I don't recommend using SQL Data Sources in a production environment, I instead prefer to seperate the data access layer and use Object Data sources. However, for the purposes of this demo, the SQKDataSource is a lot easier to demonstrate.

Make sure you include an InsertCommand and InsertParameters as shown below:

<asp:SqlDataSource ID="dsListview" ConnectionString="<%$ ConnectionStrings:MyConnection %>"
runat="server" SelectCommand="SELECT * FROM [T_Employees]"
InsertCommand="Insert into T_Employees (firstname, lastname, location, department)
values (@firstname, @lastname, @location, @department)">
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Location" Type="String" />
<asp:Parameter Name="Department" Type="String" />
</InsertParameters>
</asp:SqlDataSource>



Step 3 - Add the InsertItemTemplate

Finally, add an InsertDataTemplate which contains bound controls for your InsertParameters. I've also included validators here and a validation summary, to ensure that proper data is being entered into the database:

<InsertItemTemplate>
<tr>
<td>
&nbsp;
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server" Width="80px"
Text='<%#Bind("FirstName")%>' />
<asp:RequiredFieldValidator ID="RV1" ControlToValidate="txtFirstName"
runat="server" ErrorMessage="First Name is required." Display="Dynamic"
ValidationGroup="InsertFields">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server" Width="80px"
Text='<%#Bind("LastName")%>' />
<asp:RequiredFieldValidator ID="RV2" ControlToValidate="txtLastName"
runat="server" ErrorMessage="Last Name is required." Display="Dynamic"
ValidationGroup="InsertFields">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:TextBox ID="txtLocation" runat="server" Width="90px"
Text='<%#Bind("Location")%>' />
<asp:RequiredFieldValidator ID="RV3" ControlToValidate="txtLocation"
runat="server" ErrorMessage="Location is required." Display="Dynamic"
ValidationGroup="InsertFields">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:TextBox ID="txtDepartment" runat="server" Width="90px"
Text='<%#Bind("Department")%>' />
<asp:RequiredFieldValidator ID="RV4" ControlToValidate="txtDepartment"
runat="server" ErrorMessage="Department is required." Display="Dynamic"
ValidationGroup="InsertFields">*</asp:RequiredFieldValidator>
</td>
<td>
<asp:LinkButton ID="LinkButton1" CommandName="Insert" Text="Add"
runat="server" CausesValidation="true" ValidationGroup="InsertFields" />
</td>
</tr>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true"
ShowSummary="false" ValidationGroup="InsertFields" />
</InsertItemTemplate>
Openxcell
Experienced Developer
Experienced Developer
 
Posts: 79
Joined: Mon Mar 28, 2011 1:59 pm

Re: How to insert locations marked on maps in a dynamic list

Postby spoortigandhad » Mon Apr 11, 2011 10:22 am

Thanks for your reply.......
How to fetch values from maps? Did you mean latitude and longitude?
spoortigandhad
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Apr 11, 2011 6:28 am

Top

Return to Map Problems

Who is online

Users browsing this forum: Google [Bot] and 2 guests