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]
Using java Syntax Highlighting
- package org.apache.geocode;
- import android.app.Activity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ListView;
- import org.apache.commons.httpclient.Credentials;
- import org.apache.commons.httpclient.HttpClient;
- import org.apache.commons.httpclient.UsernamePasswordCredentials;
- import org.apache.commons.httpclient.auth.AuthPolicy;
- import org.apache.commons.httpclient.auth.AuthScope;
- import org.apache.commons.httpclient.methods.PostMethod;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
- import java.io.IOException;
- import java.util.List;
- /**
- * Uses the MapPoint Web Service to get details (of nearby locations/addresses) on a specified lat/long
- */
- public class ReverseGeoCoder extends Activity implements View.OnClickListener {
- // UI elements
- private Button mLookup;
- private EditText mUserId;
- private EditText mPassword;
- private EditText mLatitude;
- private EditText mLongitude;
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.main);
- // Gather the troops
- mUserId = (EditText) findViewById(R.id.username);
- mPassword = (EditText) findViewById(R.id.password);
- mLatitude = (EditText) findViewById(R.id.latitude);
- mLongitude = (EditText) findViewById(R.id.longitude);
- mLookup = (Button) findViewById(R.id.lookup);
- // Set up a couple of button listeners
- mLookup.setOnClickListener(this);
- }
- // SOAP Request for the FindServiceSOAP.GetLocationInfo web service
- String soapRequestXML_1 = "<?xml version="1.0" encoding="utf-8"?>n" +
- "<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" " +
- " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" " +
- " xmlns:xsd="http://www.w3.org/2001/XMLSchema">n" +
- " <soap:Body>n" +
- " <GetLocationInfo xmlns="http://s.mappoint.net/mappoint-30/">n" +
- " <location>";
- String soapRequestXML_2 = " </location>n" +
- " <dataSourceName>MapPoint.NA</dataSourceName>n" +
- " <options/>n" +
- " </GetLocationInfo>n" +
- " </soap:Body>n" +
- "</soap:Envelope>";
- /**
- * When the user clicks on the lookup button we use the MapPoint SOAP API to fetch the
- * information of the specified latitude longitude.
- *
- * @param view
- */
- public void onClick(View view) {
- String user = mUserId.getText().toString();
- String password = mPassword.getText().toString();
- String latitude = mLatitude.getText().toString();
- String longitude = mLongitude.getText().toString();
- // Use our customized Digest Auth scheme as per the following article
- // http://go.mappoint.net/MappointMPAC/def ... &id=J10002
- AuthPolicy.registerAuthScheme(AuthPolicy.DIGEST, DigestMapPointScheme.class);
- String url = "http://findv3.staging.mappoint.net/Find-30/FindService.asmx";
- HttpClient client = new HttpClient();
- client.setConnectionTimeout(8000);
- Credentials credentials = new UsernamePasswordCredentials(user, password);
- client.getState().setCredentials(AuthScope.ANY, credentials);
- PostMethod postMethod = new PostMethod(url);
- // Construct a SOAP request by hand
- StringBuffer request = new StringBuffer();
- request.append(soapRequestXML_1);
- request.append("<Latitude>").append(latitude).append("</Latitude>");
- request.append("<Longitude>").append(longitude).append("</Longitude>");
- request.append(soapRequestXML_2);
- postMethod.setRequestBody(request.toString());
- postMethod.setRequestHeader("Content-Type",
- "text/xml; charset=utf-8");
- postMethod.setRequestHeader("SOAPAction",
- ""http://s.mappoint.net/mappoint-30/GetLocationInfo"");
- int statusCode = 0;
- try {
- statusCode = client.executeMethod(postMethod);
- } catch (IOException e) {
- Log.d("ReverseGeoCoder", e.toString(), e);
- }
- Log.i("ReverseGeoCoder", "statusCode>>>" + statusCode);
- Log.i("ReverseGeoCoder", "statusLine>>>" + postMethod.getStatusLine());
- // Parse the SOAP Response
- MyContentHandler myContentHandler = new MyContentHandler();
- try {
- SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
- parser.parse(postMethod.getResponseBodyAsStream(), myContentHandler);
- } catch (Exception e) {
- Log.d("ReverseGeoCoder", e.toString(), e);
- }
- // Display the response details.
- List list = myContentHandler.getLocations();
- String[] items = new String[list.size()];
- for (int i = 0; i < list.size(); i++) {
- MyContentHandler.MyLocation location = (MyContentHandler.MyLocation) list.get(i);
- Log.i("ReverseGeoCoder", "Location : " + i);
- Log.i("ReverseGeoCoder", "Latitude : " + location.latitude);
- Log.i("ReverseGeoCoder", "Longitude : " + location.longitude);
- Log.i("ReverseGeoCoder", "Description : " + location.description);
- items[i] = location.description + " (geo:" + location.latitude + "," + location.longitude + ")";
- }
- // Show the data in the list view
- ListView listView = (ListView) findViewById(R.id.data);
- listView.setAdapter(new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_1,
- items));
- postMethod.releaseConnection();
- }
Parsed in 0.054 seconds, using GeSHi 1.0.8.4
You can download complete source code at ReverseGeoCode.zip
by vamsi



