Android avd2.2 obtains the street information: geocoder, "the service is not available" & geocoder returns the list as null, and the street information is not obtained.

Source: Internet
Author: User

"The geocoder class requires a backend service that is not supported in the core Android framework. The geocoder query methods will return an empty list if there no backend service in the platform."

Here we have mentioned that we need to have a backend service, but we have some suggestions on how to get this service. Some people in the Forum think we should use Google map API.
In the following two links, foreign friends also mentioned using map Api!

 

The documentation states: The geocoder class requires a backend service that is not supported in the core Android framework, how/Where can I obtain such a service?
It seems it's a bug in the emulator for 2.2 and there is a bug fix about it, for details

Seehttp: // code.google.com/p/android/issues/detail? Id = 8816

I have found a workaround to the issue. I used the standard Google API:

Http://code.google.com/apis/maps/documentation/geocoding/

I have created a method that requires ed a string address like "220 + Victoria + square" and returns a jsonobject with the response of the HTTP call

 

 

Public static jsonobject getlocationinfo (string address) {</P> <p> httpget = new httpget ("http://maps.google. <br/> + "com/maps/API/geocode/JSON? Address = "+ address <br/> +" Ka & sensor = false "); <br/> httpclient client = new defaulthttpclient (); <br/> httpresponse response; <br/> stringbuilder = new stringbuilder (); </P> <p> try {<br/> response = client.exe cute (httpget ); <br/> httpentity entity = response. getentity (); <br/> inputstream stream = entity. getcontent (); <br/> int B; <br/> while (B = stream. read ())! =-1) {<br/> stringbuilder. append (char) B); <br/>}< br/>} catch (clientprotocolexception e) {<br/>} catch (ioexception E) {<br/>}</P> <p> jsonobject = new jsonobject (); <br/> try {<br/> jsonobject = new jsonobject (stringbuilder. tostring (); <br/>} catch (jsonexception e) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}</P> <p> return jsonobject; <br/>} 

 

After executing this, another method converts that jsonobject into a geopoint.

Public static geopoint getgeopoint (jsonobject) {</P> <p> double Lon = new double (0); <br/> double lat = new double (0 ); </P> <p> try {</P> <p> Lon = (jsonarray) jsonobject. get ("Results ")). getjsonobject (0) <br/>. getjsonobject ("Geometry "). getjsonobject ("location") <br/>. getdouble ("LNG"); </P> <p> lat = (jsonarray) jsonobject. get ("Results ")). getjsonobject (0) <br/>. getjsonobject ("Geometry "). getjsonobject ("location") <br/>. getdouble ("Lat"); </P> <p >}catch (jsonexception e) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}</P> <p> return New geopoint (INT) (LAT * 1e6), (INT) (Lon * 1e6 )); </P> <p>} 

 

However this solution is extremely nasty and coupled ..
PS. You shoshould add

<Uses-library Android: Name = "com. Google. Android. Maps"> </uses-library> 

To androidmanifest. xml or application cocould not find geopoint class.

By the way, we recommend an android map development introductory article:

Http://mobiforge.com/developing/story/using-google-maps-android

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.