`
jacky-zhang
  • 浏览: 310015 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

About Android; Geocoder, “the service is not available”

阅读更多
The documentation states : The Geocoder class requires a backend service that is not included 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 see http://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 received a String address like "220+victoria+square" and returns a JSONObject with the response of the HTTP Call
public static JSONObject getLocationInfo(String address) {

		HttpGet httpGet = new HttpGet("http://maps.google.
				+ "com/maps/api/geocode/json?address=" + address
				+ "ka&sensor=false");
		HttpClient client = new DefaultHttpClient();
		HttpResponse response;
		StringBuilder stringBuilder = new StringBuilder();

		try {
			response = client.execute(httpGet);
			HttpEntity entity = response.getEntity();
			InputStream stream = entity.getContent();
			int b;
			while ((b = stream.read()) != -1) {
				stringBuilder.append((char) b);
			}
		} catch (ClientProtocolException e) {
		} catch (IOException e) {
		}

		JSONObject jsonObject = new JSONObject();
		try {
			jsonObject = new JSONObject(stringBuilder.toString());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return jsonObject;
	}

After executing this, another method converts that JSONObject into a GeoPoint.
public static GeoPoint getGeoPoint(JSONObject jsonObject) {

		Double lon = new Double(0);
		Double lat = new Double(0);

		try {

			lon = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
				.getJSONObject("geometry").getJSONObject("location")
				.getDouble("lng");

			lat = ((JSONArray)jsonObject.get("results")).getJSONObject(0)
				.getJSONObject("geometry").getJSONObject("location")
				.getDouble("lat");

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));

	}

However this solution is extremely nasty and coupled..
PS. you should add
<uses-library android:name="com.google.android.maps"></uses-library>
to AndroidManifest.xml or application could not find GeoPoint class.
分享到:
评论

相关推荐

    geocoder-service:简单的地理编码器服务,无外部依赖

    此仓库已移动: : 此版本将被存档一段时间。... 确保在构建过程中或直接使用脚本代码包含geocoder-service.js文件。 用法 将geocoderService注入您的控制器并按如下方式使用 $scope . latitude = null ; $scope .

    GeocoderDemo:演示显示Android Geocoder的错误的演示

    演示了如何使用边界框对Android Geocoder进行编码时出现的问题。 AOSP问题-https: id 75575 gmaps-api-issue- id=7142 用法: 运行项目 输入搜索字词(或使用默认字词) 点击“使用边界框运行Geocoder”以...

    geocoder:这是Android内置的Geocoder的独立于设备且可插拔的替代品

    这是Android内置的Geocoder的独立于设备且可插拔的替代产品。 用于处理地理编码和反向地理编码的类。 地理编码是将街道地址或其他位置描述转换为(纬度,经度)坐标的过程。 反向地理编码是将(纬度,经度)坐标...

    Android in Action

    Part 1 What is Android? — The Big Picture 1 Targeting Android 1.1 Introducing Android 1.2 Stacking up Android 1.3 Booting Android development 1.4 An Android application 1.5 Summary 2 Development ...

    Geocoder:android.location.Geocoder 的更丰富且独立于平台的替代方案

    此 Geocoder 具有与 android.location.Geocoder 类似的 API,但它是独立于设备的实现并提供更丰富的 Address 对象。 有关更多详细信息,请参阅示例项目。 最低 API 级别 7 将此添加到 build.gradle 依赖项中,将 ...

    Android应用开发详解

    Android中的GPS应用,讲述了LocationManager、LocationProvider、跟踪、定位、Geocoder正逆向编解码和可视化位置服务 第三篇 应用篇 第15章 Android应用案例——移动警务通 Android 应用案例——移动警务通,通过...

    java用geocoder相关jar文件

    java用geocoder相关jar文件,编译时需要导入这些jar包

    PlacePicker:使用Geocoder而非Google API的免费Android Map Place Picker替代品

    Google Maps的Place Picker在Android中已被弃用,并告知我们转移到付费API。 多次加载后,“自动完成”,“附近”和“地方”照片API将会收费。 幸运的是,“移动和地理编码器”上的“静态和动态地图”仍然免费。 ...

    Professional Android 4 Application Development 源代码

    Using the Intent Service to Simplify the Earthquake Update Service Chapter 10: Expanding the User Experience Introducing the Action Bar Adding an Action Bar to the Earthquake Monitor Creating and ...

    Pro Android学习:location小例子

    这是Pro Android学习系列中location部分的例子源代码。相关学习笔记见:http://blog.csdn.net/flowingflying/article/details/6212512

    ol-geocoder, OpenLayers的Geocoder Nominatim.zip

    ol-geocoder, OpenLayers的Geocoder Nominatim OpenLayers控制编码器 用于 的编码器扩展。 需要 OpenLayers或者更高。 演示你可以在这里看到演示或者在 jsFiddle,如果你愿意。 还有一个用于创建自定义提供程序插件...

    PHP移动定位应用开发库Geocoder.zip

     $adapter, '&lt;MAXMIND_API_KEY&gt;', $service, $useSsl  ),  new \Geocoder\Provider\ArcGISOnline(  $adapter, $sourceCountry, $useSsl  ), ]); $geocoder-&gt;registerProvider(  new \Geocoder\...

    Laravel开发-google-geocoder

    Laravel开发-google-geocoder 用于Laravel4/5、Slim3等的简单谷歌地理编码API v3包装器

    Wrox.Professional.Android.Application.Development

    This book is for anyone interested in creating applications for the Android mobile phone platform. It includes information that will be valuable whether you're an experienced mobile developer or ...

    Laravel开发-laravel-geocoder

    Laravel开发-laravel-geocoder 一个Laravel 5包,让地理编码变得轻而易举。

    GeoCoder.zip

    将Excel 中的文字地址转换成经纬度坐标(BD-09)。调用的百度地图的Geocoder API,使用代码前需要自己先注册一下相应的AK。

    前端项目-leaflet-geocoder-mapzen.zip

    前端项目-leaflet-geocoder-mapzen,使用mapzen搜索或自己托管的pelias geocoder api搜索(geocode)的传单插件。

    出现问题a is defined高手帮忙

    // Add the two buttons to the map mapDiv.appendChild(buttonContainerDiv); //DOM:map covers var zoomDiv = document.createElement("div"); var DIVS_TO_CREATE = ['outlineDiv', 'cornerTopDiv', '...

    Android代码-NominatimNlpBackend

    UnifiedNlp geocoder backend that uses OSM Nominatim service. Building Build using gradle. Used libraries UnifiedNlpApi License Copyright 2014-2017 microG Project Team Licensed under the Apache ...

Global site tag (gtag.js) - Google Analytics