每当googlemaps视口中心发生变化时,我都会尝试使用邮政编码向我的数据库提交查询.我知道这可以通过反向地理编码完成,例如:
google.maps.event.addListener(map, 'center_changed', function(){
newCenter();
});
...
function newCenter(){
var newc = map.getCenter();
geocoder.geocode({'latLng': newc}, function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
var newzip = results[0].address_components['postal_code'];
}
});
};
Run Code Online (Sandbox Code Playgroud)
当然,这段代码实际上并不起作用.所以我想知道如何更改这个以便从结果数组中提取邮政编码.谢谢
google-maps geocoding postal-code reverse-geocoding google-maps-api-3
我使用Android Geocoding通过Address.getLocality()方法获取当前城市.它运行良好,直到最近它似乎经常为本地返回null.这是一个例子:
try {
Geocoder c = new Geocoder(this, Locale.getDefault());
double lat = 51.481;
double lon = 0.0;
List<Address> l = c.getFromLocation(lat, lon, 5);
for (Address a: l) {
Log.i("GeocoderTest", "Locality " + a.getLocality() + " (" + a + ")");
}
} catch (IOException e) {
Log.e("GeocoderTest", "", e);
}
Run Code Online (Sandbox Code Playgroud)
现在,它会为第一个返回的地址记录以下消息:
地点null(地址[addressLines = [0:"14-18 Park Vista",1:"London Green of Greenwich,London SE10",2:"UK"],feature =,admin = null,sub-admin = null, locality = null,thoroughfare = Park Vista,postalCode = null,countryCode = GB,countryName = United Kingdom,hasLatitude = …
我不需要显示地图.但是,我需要使用gps/3g网络来定位我当前的位置ADDRESS(不长和纬度),然后将其添加到自动短信响应中以通知一个人我当前无法回复,并且包括字符串地址我目前的位置.我有短信的工作,只需要弄清楚访问gps和拉地址的方法.我见过lat/long的示例代码.也许我需要将lat/long转换为google maps API中的地址?我不确定如何去做.任何建议/代码片段/类似的教程欢迎!谢谢.:)
当我的观点消失时,我收到以下消息:
An instance 0x1c11e0 of class MKAnnotationView was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
Run Code Online (Sandbox Code Playgroud)
(上下文:0x0,属性:0x1e98d0>)
定义和启动反向地理编码的代码是:
geo=[[MKReverseGeocoder alloc] initWithCoordinate:droppedAt];
geo.delegate=self;
[geo start];
Run Code Online (Sandbox Code Playgroud)
在我解除视图之前,我已经尝试将geo.delegate设置为nil.那太简单了.我也尝试过:
for (id <MKAnnotation> annotation in mvMap.annotations) {
[[mvMap viewForAnnotation:annotation] removeObserver:self forKeyPath:@"selected"];
}
Run Code Online (Sandbox Code Playgroud)
这引发了一个错误:
*由于未捕获的异常'NSRangeException'而终止应用程序,原因是:'无法删除"选中"的关键路径的观察者,因为它未注册为观察者.
我对注释代码的看法是:
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
MKAnnotationView …Run Code Online (Sandbox Code Playgroud) 我熟悉两种反向地理编码API - Google Maps和foursquare.两者都有问题.考虑lat,lng = 35.699,139.707(东京).
四方:
GET https://api.foursquare.com/v2/venues/search?ll=35.699,139.707&oauth_token=5TJR4WQZSOW0ZWTE4ENMXKO3Y415252GITEMRPQIVPMEGCYK&v=20120723&limit=1
Run Code Online (Sandbox Code Playgroud)
得到以下结果:
{
"meta": {
"code": 200
},
"notifications": [
{
"type": "notificationTray",
"item": {
"unreadCount": 0
}
}
],
"response": {
"venues": [
{
"id": "4b64ebedf964a520e3d92ae3",
"name": "????????? ?????",
"contact": {
"phone": "0352911870",
"formattedPhone": "03-5291-1870"
},
"location": {
"address": "???1-1-45",
"crossStreet": "????????????? 1F",
"lat": 35.698492646211,
"lng": 139.707271456718,
"distance": 61,
"postalCode": "169-0072",
"city": "???",
"state": "???",
"country": "Japan",
"cc": "JP"
},
"categories": [
{
"id": "4bf58dd8d48988d111941735",
"name": "Restaurant japonais",
"pluralName": "Restaurants japonais", …Run Code Online (Sandbox Code Playgroud) 我想从纬度和经度中找到当前位置名称,
这里是我的代码片段我试过,但我的日志显示,除了在所有的地方空值placemark,placemark.ISOcountryCode和placemark.country
我想要的价值placemark.locality,并placemark.subLocality却是露出空值.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// this creates the CCLocationManager that will find your current location
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
}
// this delegate is called when the app successfully finds your current location
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!"); …Run Code Online (Sandbox Code Playgroud) 我需要一个函数来使用谷歌地图api反向地理编码和php从坐标(lat,long)获取最近的地址或城市...请提供一些示例代码
我一直在努力在Google地图中整合反向地理编码的Javavscript代码.我以为我已经解决了我遇到的所有问题,但我仍然遇到问题.
当我在HTML文件中嵌入Javascript代码时,它没有任何问题.但是,如果我尝试运行javascript(带有一些改动),作为一个单独的文件,地图会在打开我的表单时加载,但是当我输入Lat和Lng坐标并按相关按钮来反转地理编码时,所有发生的事情都会发生是地图刷新.
我已经附加了JS代码嵌入的HTML文件,然后是单独的JS代码文件进行比较.
嵌入了Javascript的HTML文件
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Reverse Geocoding</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
var infowindow = new google.maps.InfoWindow();
var marker;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(40.730885,-73.997383);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: 'roadmap'
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function codeLatLng() {
var lat = …Run Code Online (Sandbox Code Playgroud) 我正在根据本文开发一个具有反向地理编码功能的iOS应用程序:地理编码教程
但是当我在模拟器上测试时,我得到'kCLErrorDomain错误9'.我搜索了很多,只有错误0或1而不是9.
这是我的代码viewDidLoad:
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 80.0;
[self.locationManager startUpdatingLocation];
CLGeocoder *geocoder = [[[CLGeocoder alloc] init] autorelease];
[geocoder reverseGeocodeLocation:self.locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
if(placemarks && placemarks.count > 0)
{
//do something
CLPlacemark *topResult = [placemarks objectAtIndex:0];
NSString *addressTxt = [NSString stringWithFormat:@"%@ %@,%@ %@",
[topResult subThoroughfare],[topResult thoroughfare],
[topResult locality], [topResult administrativeArea]];
NSLog(@"%@",addressTxt);
}
}];
Run Code Online (Sandbox Code Playgroud)
非常感谢你.
android ×3
geocoding ×2
google-maps ×2
ios ×2
iphone ×2
google-code ×1
gps ×1
ipad ×1
javascript ×1
location ×1
osmdroid ×1
php ×1
postal-code ×1