使用google MAP座標搜尋改善用戶體驗

效果如下:

核心方法:

function szb(i){
	i=$(i);if(!i){return false;}
	adr=i.get('value');
	if(adr==''){return false;}

	var geocoder=new google.maps.Geocoder();
	var LatLng=new google.maps.LatLng(23.7,121);
	geocoder.geocode({'address':adr},function(results,status){
		if(status==google.maps.GeocoderStatus.OK){
			LatLng=results[0].geometry.location;
			lat=(LatLng.lat()).round(7);
			lng=(LatLng.lng()).round(7);
			i.set('value',lat+','+lng);
			iMap3_Marker({'mess':'<b>'+adr+'</b>','lat':lat,'lng':lng,'zom':14,'spop':false,'box':'map','icon':'/img/beachflag.png'});
			tp(i,{'htm':adr+'的座標值是:<br>'+lat+'<br>'+lng});
		}else{
			i.set('value','');
			tp(i,{'htm':adr+'的座標值沒有找到,請嘗試更換關鍵字!'});
		}
	});
}
原文地址:https://www.cnblogs.com/see7di/p/2747089.html