Android - Using Microsoft Map point web service

Tutorials that use the MapActivity. Many using GPS functionality.

Android - Using Microsoft Map point web service

Postby gvkreddyvamsi » Thu Jan 31, 2008 10:09 am

Android - Reverse GeoCode - find information about a specified lat/long using MapPoint Web Service

Here’s a sample on how to use Microsoft’s MapPoint SOAP API to get information on a specified latitude/longitude

1. Introcuction and getting started
http://msdn2.microsoft.com/en-us/library/aa492550.aspx
2. Signup for mappoint account
https://mappoint-css.live.com/MwsSignUp/Default.aspx
3. Mappoint WSDl
http://staging.mappoint.net/standard-30/mappoint.wsdl
4. Web based Demo Page
http://demo.mappoint.net/fourthcoffeeco ... cationinfo

Here is the application




[hr]
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.apache.geocode;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.ArrayAdapter;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.ListView;
  11. import org.apache.commons.httpclient.Credentials;
  12. import org.apache.commons.httpclient.HttpClient;
  13. import org.apache.commons.httpclient.UsernamePasswordCredentials;
  14. import org.apache.commons.httpclient.auth.AuthPolicy;
  15. import org.apache.commons.httpclient.auth.AuthScope;
  16. import org.apache.commons.httpclient.methods.PostMethod;
  17.  
  18. import javax.xml.parsers.SAXParser;
  19. import javax.xml.parsers.SAXParserFactory;
  20. import java.io.IOException;
  21. import java.util.List;
  22.  
  23. /**
  24.  * Uses the MapPoint Web Service to get details (of nearby locations/addresses) on a specified lat/long
  25.  */
  26. public class ReverseGeoCoder extends Activity implements View.OnClickListener {
  27.  
  28.     // UI elements
  29.     private Button mLookup;
  30.     private EditText mUserId;
  31.     private EditText mPassword;
  32.     private EditText mLatitude;
  33.     private EditText mLongitude;
  34.  
  35.     public void onCreate(Bundle icicle) {
  36.         super.onCreate(icicle);
  37.         setContentView(R.layout.main);
  38.  
  39.         // Gather the troops
  40.         mUserId = (EditText) findViewById(R.id.username);
  41.         mPassword = (EditText) findViewById(R.id.password);
  42.         mLatitude = (EditText) findViewById(R.id.latitude);
  43.         mLongitude = (EditText) findViewById(R.id.longitude);
  44.         mLookup = (Button) findViewById(R.id.lookup);
  45.  
  46.         // Set up a couple of button listeners
  47.         mLookup.setOnClickListener(this);
  48.     }
  49.  
  50.     // SOAP Request for the FindServiceSOAP.GetLocationInfo web service
  51.     String soapRequestXML_1 = "<?xml version="1.0" encoding="utf-8"?>n" +
  52.             "<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" " +
  53.             "               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" " +
  54.             "               xmlns:xsd="http://www.w3.org/2001/XMLSchema">n" +
  55.             "  <soap:Body>n" +
  56.             "    <GetLocationInfo xmlns="http://s.mappoint.net/mappoint-30/">n" +
  57.             "      <location>";
  58.     String soapRequestXML_2 = "      </location>n" +
  59.             "      <dataSourceName>MapPoint.NA</dataSourceName>n" +
  60.             "      <options/>n" +
  61.             "    </GetLocationInfo>n" +
  62.             "  </soap:Body>n" +
  63.             "</soap:Envelope>";
  64.  
  65.     /**
  66.      * When the user clicks on the lookup button we use the MapPoint SOAP API to fetch the
  67.      * information of the specified latitude longitude.
  68.      *
  69.      * @param view
  70.      */
  71.     public void onClick(View view) {
  72.  
  73.         String user = mUserId.getText().toString();
  74.         String password = mPassword.getText().toString();
  75.         String latitude = mLatitude.getText().toString();
  76.         String longitude = mLongitude.getText().toString();
  77.  
  78.         // Use our customized Digest Auth scheme as per the following article
  79.         // http://go.mappoint.net/MappointMPAC/def ... &id=J10002
  80.         AuthPolicy.registerAuthScheme(AuthPolicy.DIGEST, DigestMapPointScheme.class);
  81.  
  82.         String url = "http://findv3.staging.mappoint.net/Find-30/FindService.asmx";
  83.         HttpClient client = new HttpClient();
  84.         client.setConnectionTimeout(8000);
  85.  
  86.         Credentials credentials = new UsernamePasswordCredentials(user, password);
  87.         client.getState().setCredentials(AuthScope.ANY, credentials);
  88.  
  89.         PostMethod postMethod = new PostMethod(url);
  90.  
  91.         // Construct a SOAP request by hand
  92.         StringBuffer request = new StringBuffer();
  93.         request.append(soapRequestXML_1);
  94.         request.append("<Latitude>").append(latitude).append("</Latitude>");
  95.         request.append("<Longitude>").append(longitude).append("</Longitude>");
  96.         request.append(soapRequestXML_2);
  97.         postMethod.setRequestBody(request.toString());
  98.         postMethod.setRequestHeader("Content-Type",
  99.                 "text/xml; charset=utf-8");
  100.         postMethod.setRequestHeader("SOAPAction",
  101.                 ""http://s.mappoint.net/mappoint-30/GetLocationInfo"");
  102.  
  103.         int statusCode = 0;
  104.         try {
  105.             statusCode = client.executeMethod(postMethod);
  106.         } catch (IOException e) {
  107.             Log.d("ReverseGeoCoder", e.toString(), e);
  108.         }
  109.  
  110.         Log.i("ReverseGeoCoder", "statusCode>>>" + statusCode);
  111.         Log.i("ReverseGeoCoder", "statusLine>>>" + postMethod.getStatusLine());
  112.  
  113.         // Parse the SOAP Response
  114.         MyContentHandler myContentHandler = new MyContentHandler();
  115.         try {
  116.             SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
  117.             parser.parse(postMethod.getResponseBodyAsStream(), myContentHandler);
  118.         } catch (Exception e) {
  119.             Log.d("ReverseGeoCoder", e.toString(), e);
  120.         }
  121.  
  122.         // Display the response details.
  123.         List list = myContentHandler.getLocations();
  124.         String[] items = new String[list.size()];
  125.         for (int i = 0; i < list.size(); i++) {
  126.             MyContentHandler.MyLocation location = (MyContentHandler.MyLocation) list.get(i);
  127.             Log.i("ReverseGeoCoder", "Location : " + i);
  128.             Log.i("ReverseGeoCoder", "Latitude : " + location.latitude);
  129.             Log.i("ReverseGeoCoder", "Longitude : " + location.longitude);
  130.             Log.i("ReverseGeoCoder", "Description : " + location.description);
  131.             items[i] = location.description + " (geo:" + location.latitude + "," + location.longitude + ")";
  132.         }
  133.         // Show the data in the list view
  134.         ListView listView = (ListView) findViewById(R.id.data);
  135.         listView.setAdapter(new ArrayAdapter<String>(this,
  136.                 android.R.layout.simple_list_item_1,
  137.                 items));
  138.         postMethod.releaseConnection();
  139.     }
Parsed in 0.055 seconds, using GeSHi 1.0.8.4
[hr]


You can download complete source code at ReverseGeoCode.zip

by vamsi
gvkreddyvamsi
Developer
Developer
 
Posts: 43
Joined: Mon Jan 21, 2008 5:10 am
Location: INDIA

Top

Postby cabernet1976 » Thu Jul 03, 2008 8:00 am

Hi gvkreddyvamsi,
How do you think about this class android.location.Address? It seems be able to implement your feature.
Thanks.
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Postby jeyavelnkl » Tue Jan 12, 2010 11:33 am

Hi gvkreddyvamsi,

i have used your code and i have added "org.apache.commons.httpclient.Jar" file with my application and then gave mappoint user crediential .

while executing below line code in emulator i am getting exception like

DEBUG/ReverseGeoCoder(912): java.net.UnknownHostException: findv3.staging.mappoint.net - findv3.staging.mappoint.net

and i am getting statuscode and StatusLine Null value

try {
statusCode = client.executeMethod(postMethod);
} catch (IOException e) {
Log.d("ReverseGeoCoder", e.toString(), e);
}


and MyContentHandler(here i am getting error "MyContentHandler cannot be resolved to a type")

my Environemnt:
Eclipse 3.5.1
Google Api 1.5 Platform
Emulator.


Can you tell me any way to resolve this issue?

Thx
jeyavelnkl
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 12, 2010 10:28 am
Location: India

questions..

Postby mmgill » Sat Mar 13, 2010 8:29 pm

hi guys.
i was just trying to mess around with the MapPoint Service and was wondering if there was a link to the ReverseGeoCode.zip file list at the end of the post (it seems to be broken)? Also, to test on an emulator do you need to put mock data in for the location? Thanks for the help!
mmgill
Junior Developer
Junior Developer
 
Posts: 20
Joined: Thu Mar 04, 2010 8:40 pm

Re: Android - Using Microsoft Map point web service

Postby Avw » Tue Oct 26, 2010 10:32 am

Hi ...
Im not able to download the source code for reverse geocode... Is thr anothr link..if so pls post it....
Avw
Freshman
Freshman
 
Posts: 4
Joined: Tue Oct 12, 2010 8:20 am

Top

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest